开发者

Format a Large Number [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:开发者_开发百科

How to format a number from 1123456789 to 1,123,456,789 in C?

How can I format a large integral number with commas in C, such that the readability is improved?

222222 should be 222,222 and 44444444 should be 44,444,444.


You do not need to do the formatting yourself; printf in Unix has a ' modifier:

printf("%'d\n", number);

It looks like Visual Studio doesn't support that. This syntax is locale-aware, however.


Use the modulus (%) operation and build your own string.


If you google for "c format thousands separator" then one of the hits is this page http://www.codeguru.com/forum/archive/index.php/t-402370.html
It's C++ though but it should give you an idea of what you can do.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜