|
-
April 20th, 2004, 11:24 AM
#1
atof behaviour
Hello,
My problem :
atof('5.2') returns 0 if the regional settings indicate that the decimal caracter is ',' as it's usually the case in France and some other countries...
Have you ever seen it before (not me...) ? How can I do to be independant of the regional settings ?
Thanks and a great day for everybody.
Olivier
-
April 20th, 2004, 11:46 AM
#2
hi,
you have formated the output wrong or your variable is wrong ...
i didn't look at my settings, but:
function call output
------------------------------------------------
printf("%f\n",atof("5.2")); => 5.2
printf("%f\n",atof("5,2")); => 5.0
printf("%d\n",atof("5.2")); => -859...
printf("%d\n",atof("5,2")); => 0
printf("%f\n",atof('5.2')); => crash because of the ' sign ;-)
kind of regards,
typecast
-
April 20th, 2004, 12:08 PM
#3
Re: atof behaviour
Originally posted by Olivier DUGRAND
How can I do to be independant of the regional settings ?
I think your demands are unreasonable. You will be surprised, but symbols other than '.' and ',' might be used to separate decimal part.
What's wrong with looking into current locale? Use localeconv(), for example.
Or if you know for sure what separator is used in your string, you could set locale yourself before that conversion.
Also, not because of the locale (it would have returned 5), but because your string must be enclosed in quotes: "5.2"
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
April 23rd, 2004, 11:03 AM
#4
Hello Typecast and Vladimir,
Thanks for your help.
I know this problem is quite astonishing. And you are right Vladimir, I made a mistake writing "atof('5.2')". Of course, the value passed to atof is a string.
The fact is and stay that when the local setting are is set to ',' atof doesn't work and when '.' is set, atof works correctly.
However, I will follow your advises and if it works, I'll tell you.
Thanks for all.
Olivier
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|