BigInteger.ToString () returns more than 50 decimal digits

I am using the .NET 4 System.Numerics.BigInteger Structure and I get results other than documentation.

The documentation of the BigInteger.ToString () Method It says:

The ToString () method supports 50 decimal digits of precision. That is, if a BigInteger value has more than 50 digits, only 50 significant digits are stored in the output line; all other digits are replaced with zeros.

I have a code that takes 60 decimal digits of BigInteger and converts it to string . 60 significant decimal digits of string not lost significant digits:

 const string vString = "123456789012345678901234567890123456789012345678901234567890"; Assert.AreEqual(60, vString.Length); BigInteger v = BigInteger.Parse(vString); Assert.AreEqual(60, v.ToString().Length); Assert.AreEqual('9', v.ToString()[58]); Assert.AreEqual('1', v.ToString()[0]); Assert.AreEqual(vString, v.ToString()); Assert.AreEqual(vString, v.ToString("G")); 

All statements pass.

What exactly does the quoted part of the document mean?

+1
tostring biginteger
source share
1 answer

The documentation here is a bit unclear, this limit applies only to formatting , for example:

 v.ToString("0"); "123456789012345678901234567890123456789012345678900000000000" v.ToString("n0"); "123,456,789,012,345,678,901,234,567,890,123,456,789,012,345,678,900,000,000,000" 

The exception is formatting it as "R" , which gives the original rounding value:

 v.ToString("R"); "123456789012345678901234567890123456789012345678901234567891" 
+3
source share

All Articles