Remove E sign from big float number , C#?

2020-07-14 12:45发布

问题:

If you used big float numbers , you found in C# big float number is showed like this :
2000000 * 2000000 = 4E+12

How can I show 4E+12 as 4,000,000,000,000 not 4E+12 ?

回答1:

You want

number.ToString("N0");

"N0" is Number with no decimal places.

The alternative - "F0" is Fixed-point with no decimal places but prints without the comma separators:

double number = 4e12;
Console.WriteLine(number.ToString("F0"));
Console.WriteLine(number.ToString("N0"));

prints:

4000000000000
4,000,000,000,000

Source



回答2:

Really great answer!

My code is

Double dblAcct = (Double)childRow["Account No"];
s_acct = dblAcct.ToString("F0");
s_acct = s_acct.PadLeft(16, '0');