开发者

Make a long int easier to read

开发者 https://www.devze.com 2023-04-11 11:17 出处:网络
I\'开发者_运维百科m working on a fairly simple console application but I got one little problem. It\'s very hard to read large numbers unless you go close to the monitor and look very carefully. It\'s

I'开发者_运维百科m working on a fairly simple console application but I got one little problem. It's very hard to read large numbers unless you go close to the monitor and look very carefully. It's very important that the user immediately can see how much it is. For example, which of these is the easiest to read?

143000532
143.000.532

I want it to look like the second one. It's fairly simple to just do an if every time I need to print a large number but that's tedious and makes the code look bad. Is there any way I can do this in a beautiful way and still be able to use the variable in calculations and comparisons?


int intValue = 123456789;
Console.WriteLine(intValue.ToString("N", CultureInfo.InvariantCulture));

and you will get 123,456,789.00

edit: if you want to eliminate the decimal point use this:

Console.WriteLine(intValue.ToString("N0", CultureInfo.InvariantCulture));


string.Format("{0:n}", 143000532);

Will result in 143,000,532.0

Or if you don't want decimals...

string.Format("{0:n0}", 143000532);

Will result in 143,000,532

0

精彩评论

暂无评论...
验证码 换一张
取 消