Frage

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

War es hilfreich?

Lösung 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.

Andere Tipps

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)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top