0

is there a manipulator in C++ that do that ?

if not how can i cout my numbers formatted that way .

if the number is larger than 999.99 i want to put a comma after the first 3 digits and after the 6 digits ..etc

x = 99456
Example : cout << X

shows in the screen : 99,456 instead of 99456 .

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by evanovan
0

Read this thread

thanks a lot. i thought there is a manipulator the can do the job directly.

is this the easiest way "fixed a couple of bugs (brute force version). "

it seems too long for adding a comma for the thousand / million ranges

0

That is only one way to do it. A more generic way would be to first convert the int to string, then copy the digits in reverse order (from right to left) into another string adding the commas. Finally you will have to reverse the result string because it will be backwards. std::reverse() will do that.

0

A more generic way would be to first convert the int to string, then copy the digits in reverse order (from right to left) into another string adding the commas. Finally you will have to reverse the result string because it will be backwards. std::reverse() will do that.

Unless you copy into the string starting at the end of the destination string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.