Syntax for printing commas in numerics
I've got a program I need a mortgage table printed as an output and I'm struggling with the syntax for printing commas in the digits(ex. 20,000 instead of 20000).
cin >> prin;
if (prin == 20,000)
cout << myTable << endl;
Not only do i need it to print in the table will it matter if its the user input for prin? Thanks for any and all help!
So, you are trying to insert commas into the numbers, then print them?
Typically you need to imbue the stream with a locale that automatically does that for you.
For example, on Linux, my locale is en_US.UTF-8.
If I do:
const int x = 1000000;
std::cout << x << std::endl;
The nice thing about this is that it formats the number properly for whatever locale is appropriate for the user.
A German might see this:
$ LANG=de_DE.UTF-8 ./locale_test
Last edited on
That works fine on Linux, but locale support is typically broken on Windows. MinGW users must use STLPort or some other standard library to get C++ locale support of any kind.
The code works just fine with VS2010.
Topic archived. No new replies allowed.