How to prevent Long / Int64 ToString () from converting to Exponential format?

Running .NET 4.6 and x64 build options

The No ToString () format option seems to work for numbers longer than 15 digits, 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:

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

However, I would prefer a prime. I would prefer not to use:

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

Any suggestions?

Edit: The solution has already been tried .. ToString ("0")

Perform a full VS2015 repair and clean my solution. Now he is working as intended.

+4
source share
3 answers

You can use the format "0".

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

Output: Str = 1234567890123456789

+4
source

If you really got long or ulong , then

 string s = long.MaxValue.ToString() ; 

returns the expected string "9223372036854775807" .

While

 string s = ulong.MaxValue.ToString() ; 

returns the expected string "18446744073709551615" .

Are you sure you are dealing with long , not a floating point type?

+1
source
 Int64 bigNumber = 9223372036854775806L; String s1 = String.Format("{0:g}", bigNumber); String s2 = bigNumber.ToString("G"); Debug.WriteLine("s1 = {0}, s2 = {1}", s1, s2); 

writes:

s1 = 9223372036854775806, s2 = 9223372036854775806

0
source

All Articles