Use decimal separator from Regional Settings in CString.Format()

1.2k views Asked by At

I try to display my number using the separator from my current regional settings.

Here is my code:

Cstring result;    
Cstring myMeasure;  

myMeasure.Format(_T("%.6f %s"), myDouble, myUnit));
result.Format("My volume is: %s", myMeasure);

result equals for example "My volume is: 4.565600 mL". But using french regional settings, the result is still the same (whereas French decimal separator is comma instead of period).

I tried the setlocale() method unsucessfully.

char* originalCulture = setlocale(LC_ALL, NULL); // save original culture
setlocale(LC_ALL,"");

Cstring result;    
Cstring myMeasure;  

myMeasure.Format(_T("%.6f %s"), myDouble, myUnit));
result.Format("My volume is: %s", myMeasure);

setlocale(LC_ALL, originalCulture); // restore original culture

Can someone help me on that?

1

There are 1 answers

1
SingerOfTheFall On

You should call setlocale(LC_ALL, "") or setlocale(LC_ALL, "your_locale") before doing anything else to apply the locale. The former sets the default locale of the operating system, the latter sets a particular locale. Also consider checking this MSDN article for additional info about setlocale.