Why one should not use function atof() to convert string to double?
On success, atof() function returns the converted floating point number as a double value.
If no valid conversion could be performed, the function returns zero (0.0).
If the converted value would be out of the range of representable values by a double, it causes undefined behavior.
Refrence:http://www.cplusplus.com/reference/cstdlib/atof/
Instead use function strtod(), it is more robust.
Try this code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char s[100] = "4.0800";
printf("Float value : %4.8f\n",strtod(s,NULL));
return 0;
}
You will get the following output:
Float value : 4.08000000