开发者

Make a long int easier to read

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜