Question

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

Était-ce utile?

La solution 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.

Autres conseils

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)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top