BigInteger.ToString() returns more than 50 decimal digits.

Posted by brickner on Stack Overflow See other posts from Stack Overflow or by brickner
Published on 2010-06-06T12:40:13Z Indexed on 2010/06/06 12:42 UTC
Read the original article Hit count: 205

Filed under:
|
|

I'm using .NET 4 System.Numerics.BigInteger Structure and I'm getting results different from the documentation.

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

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

I have some code that takes a 60 decimal digits BigInteger and converts it to a string. The 60 significant decimal digits string didn't lose any 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());

All the asserts pass.

What exactly does the quoted part of the documentation mean?

© Stack Overflow or respective owner

Related posts about .net-4.0

Related posts about tostring