Does anyone have a simple c++ function that will format a number i.e. 1000 = 1,000 / 5000000 = 5,000,000 etc... ? I am new to c++ so if I need to include anything or add header files please let me know.
Thanks in advance!
Jas
This is a discussion on number format within the C++ Programming forums, part of the General Programming Boards category; Does anyone have a simple c++ function that will format a number i.e. 1000 = 1,000 / 5000000 = 5,000,000 ...
Does anyone have a simple c++ function that will format a number i.e. 1000 = 1,000 / 5000000 = 5,000,000 etc... ? I am new to c++ so if I need to include anything or add header files please let me know.
Thanks in advance!
Jas
Convert the number to a (preferably C++) string using stringstreams, or any of the numerous other methods that will get mentioned. Then go through the string backwards (aka starting at the end), and every three characters insert a comma.
well that is what i tried but i couldn't get my head around the function so i was wondering if anyone had some sample code?
If you tried it, show us your code.
Help needed. Simple C++ program.
My post in the above thread, #19, shows how to use a feature of the language (somewhat complex for beginners) that takes care of this for you. It would however be far easier for most to simply manipulate a string containing the value by inserting commas where appropriate as has already been suggested.
I used to be an adventurer like you... then I took an arrow to the knee.