The standard says to atof:
Except for the behaviour on error, it is equivalent to strtod(nptr,(char**)NULL)
so yours returning '0' has nothing to do with a float not being able to represent it or similar.
Would you use strtod instead (which you probably should when stringstreams are not an option, just to be able to report errors), then you would likely notice that it stops parsing at the .
.
This is a strong indication that you are using a locale that awaits ,
instead of .
as s decimal separator. Depending on how your application works with locales, you might want to run it with a properly set environment variable (e.g. LC_NUMERIC=C
) or do a setlocale(LC_NUMERIC,"C");
yourself before any parsing.
In any case you should analyze who in your application is using locale dependent things, and what for, so as to not collide with them. Another possible route is to require locale dependent input everywhere, so everyone needs to give the numbers to you with ,
as decimal separator.