Format complex number with standard format letters in CSharp

Description

The following code shows how to format complex number with standard format letters.

Example


/*from w  w w  .ja va  2s . com*/
using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      Complex[] c = { new Complex(1117.3, 1114.1), new Complex(-11.154, -17.002) };
      string[] formats = { "F2", "N2", "G5" }; 

      foreach (Complex c1 in c)
      {
         foreach (string format in formats)
            Console.WriteLine("{0}: {1}    ", format, c1.ToString(format));
      }                          
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var