Mega Code Archive

 
Categories / C# / Data Types
 

Converts BigInteger to string using culture-specific format information

using System; using System.Numerics; using System.Globalization; public class Example {    public static void Main()    {         // Redefine the negative sign as the tilde for the invariant culture.         NumberFormatInfo bigIntegerFormatter = new NumberFormatInfo();         bigIntegerFormatter.NegativeSign = "~";                  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,                               bigIntegerFormatter));    } }