atof and locale


I changed the locale in my control-pannel to French so the number "123,456.50" should be displayed as "123 456,50" The locale settings
Now I put in my C++ program:
double f=atof("123 456,50").
So I should get it, but I get 126
Also, I did
double f=123456.50;
and sprintf(str,"%.02f",f);
I see in str (123456.50)  and not (123456,50 as I expected).

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VapiSoftAuthor Commented:
OK, I found the soultion.
You need to add:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Use the GetNumberFormat() to format your number string.

The following shows how the GetNumberFormat API is used to
format a given number string for the current user locale
(using the default settings for number formatting that the user has defined):

GetNumberFormat(LOCALE_USER_DEFAULT,  // locale (current user locale)
                               0,                                            // options
                               TEXT("1234567890.12345"), // input string (see MSDN for legal chars)
                               NULL,                                     // formatting information
                               g_szTemp,                             // formatted string buffer
                              MAX_STR);                             // size of buffer

(Taken from:
VapiSoftAuthor Commented:
This does not do what I want.
What I need is to get the float number from a string that is formatted using the current locale.

I found the solution:
You need to add
and then atof("123456,50) will return the right number.
BUT, it does not reconize the sapce, so "123 456,50) will return 123.
I can overcome this problem (by converting any number to a number without spaces).
VapiSoftAuthor Commented:
As I wrote, this soves most of the problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.