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

Was it helpful?

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.

OTHER TIPS

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top