Use atof()
or strtof()
printf("float value : %f\n" ,atof(s));
printf("float value : %f\n" ,strtof(s, NULL));
NOTE strtof()
require C99 or C++11.
Pregunta
I require to convert strings to decimals in C. The strings are of the form -0.841986 and 60.751800.
Would be grateful to learn if there are functions or if not ways to do the required.
Thanks
Solución 2
Use atof()
or strtof()
printf("float value : %f\n" ,atof(s));
printf("float value : %f\n" ,strtof(s, NULL));
NOTE strtof()
require C99 or C++11.
Otros consejos
Have a look at the functions strtod()
(converting a C string to a double
), strtof
(converting a C string to float
) and strtold()
(converting a C string to a long double
)