strtod
Converts a string to double representation
#include <limits.h> #include <stdlib.h> double strtod ( const char *ptr, char **endptr);
strtod returns the converted value. If the correct value causes overflow, plus or minus HUGE_VAL is returned according to the sign, and errno is set to ERANGE. If the correct value causes underflow, a value of 0 is returned, and errno is set to ERANGE. A value of 0 is returned when the input string cannot be converted.
The strtod function converts the string pointed to by ptr to double representation. The function recognizes a string containing:
The conversion ends at the first unrecognized character. A pointer to that character is stored in the object to which endptr points if endptr is not NULL.
#include <limits.h> #include <stdlib.h> double convert_pi () { double pi; pi = strtod ("3.141592653589793", NULL) return (pi); }