Search code examples
cstringdecimaltypeconverter

Converting strings to signed decimal in C


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


Solution

  • 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.