문제

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

도움이 되었습니까?

해결책 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.

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top