28547_user
28547_user

Reputation: 89

Format thousands separator

I am programming in c++ using mfc in visual studio 2010.

I live in Europe, so I have the regional settings of the PC not USA but Europe.

I use the .Format function of CString to print the result of a calculation and I want to add a decimal point as separator between hundred and thousands.

For example, I would like to have displayed 23.400 instead of 23400

Is it possible using a particular formatting of % or i have to change the setting of the pc?

Thanks for the help

Upvotes: 2

Views: 1748

Answers (2)

Jerry Coffin
Jerry Coffin

Reputation: 489998

As far as I know CString's .Format doesn't support this.

I'd use a stringstream to handle the formatting:

std::ostringstream temp;
temp.imbue(std::locale(""));

temp << 23400;

CString result = temp.str().c_str();

Specifying an empty string as the name of the locale as I've done here means it should pick up the locale setting from the OS. You can give the name of a specific locale instead (e.g., if you want a specific locale, regardless of how the OS is configured):

temp.imbue(std::locale("de")); // German locale

Upvotes: 5

matt2405
matt2405

Reputation: 171

As far as I know this is what your are looking for. Simple search on google gave the answer. This type of print (%.2f) by the way is pretty standard among pretty much every modern language.

"Floating point: %.2f\n"

https://msdn.microsoft.com/en-us/library/aa314327(v=vs.60).aspx

Upvotes: 0

Related Questions