C# Complex ToString(String, IFormatProvider)

Description

Complex ToString(String, IFormatProvider) Converts the value of the current complex number to its equivalent string representation in Cartesian form by using the specified format and culture-specific format information for its real and imaginary parts.

Syntax

Complex.ToString(String, IFormatProvider) has the following syntax.


public string ToString(
  string format,
  IFormatProvider provider
)

Parameters

Complex.ToString(String, IFormatProvider) has the following parameters.

  • format - A standard or custom numeric format string.
  • provider - An object that supplies culture-specific formatting information.

Returns

Complex.ToString(String, IFormatProvider) method returns The string representation of the current instance in Cartesian form, as specified by format and provider.

Example


using System;//ww  w  .j a  va2 s.c  o  m
using System.Globalization;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      Complex[] c = { new Complex(17.3, 14.1), 
                      new Complex(-11.14, -17.002) };
      CultureInfo[] cultures = { new CultureInfo("en-US"), 
                                 new CultureInfo("fr-FR") }; 
      string[] formats = { "F2", "N2", "G5" }; 

      foreach (Complex c1 in c)
      {
         foreach (string format in formats)
         {
            Console.Write("{0} format string:   ", format);
            foreach (CultureInfo culture in cultures)
               Console.Write("{0} ({1})    ", c1.ToString(format, culture), culture.Name);

            Console.WriteLine();
         }
         Console.WriteLine();
      }                          
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex