👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.

In C, how to convert a string to double ?

In C / C++, atof() is a dedicated function for converting strings to floats (or doubles). First, include stdlib.h:

#include <stdlib.h>

Then, simply convert strings to floats (or doubles) :

char string[] = "10.66814";
float value = atof(string);

Test the previous code online on OneCompiler.


If the first sequence of non-whitespace characters in string does not form a valid floating-point number, the function atof() returns 0.0.

More