Search code examples
c#.netlong-integerint64

How do I prevent Long / Int64 ToString() converting to Exponential Format?


Running .NET 4.6 and x64 build options.

No ToString() format option seems to work for numbers over 15 digits in length, as it converts them to Exponential Format.

What I have tried so far:

long.ToString("#");
long.ToString("G");
long.ToString("0");
long.ToString("#,#");
long.ToString("0,0");

The only thing that partially works is:

long.ToString("0,0");  //Ex.) 5,149,673,432,170,230

However, I would prefer a plain number. I would prefer not to use:

String.Replace(",", "");

Any suggestions?

Edit: Solution was one already tried. .ToString("0")

Ran a full repair of VS2015 and Cleaned my solution. It's now working as intended.


Solution

  • You can use the "0" format.

    long num = 1234567890123456789;
    System.Diagnostics.Debug.WriteLine("Str=" + num.ToString("0"));
    

    Output: Str=1234567890123456789