C# BigInteger ToString(String)

Description

BigInteger ToString(String) Converts the numeric value of the current BigInteger object to its equivalent string representation by using the specified format.

Syntax

BigInteger.ToString(String) has the following syntax.


public string ToString(
  string format
)

Parameters

BigInteger.ToString(String) has the following parameters.

  • format - A standard or custom numeric format string.

Returns

BigInteger.ToString(String) method returns The string representation of the current BigInteger value in the format specified by the format parameter.

Example


using System;/*from   ww  w. j  a va2  s.c o  m*/
using System.IO;
using System.Numerics;

public class Example
{
   public static void Main()
   {
        BigInteger originalNumber = BigInteger.Pow(UInt64.MaxValue, Byte.MaxValue);
        string generalString = originalNumber.ToString("G");
        string roundTripString = originalNumber.ToString("R");
        Console.WriteLine("The original value has {0} hexadecmal digits.\n", 
                          originalNumber.ToString("X").Length);
        
        
        BigInteger value = BigInteger.Parse("-903145792771643190182");
        string[] specifiers = { "C", "D", "D25", "E", "E4", "e8", "F0", 
                                "G", "N0", "P", "R", "X", "0,0.000", 
                                "#,#.00#;(#,#.00#)" };
        
        foreach (string specifier in specifiers)
           Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));

    
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex