strtod

convert a string to a double

Synopsis:

#include <stdlib.h>
double strtod( const char *ptr, char **endptr );

Description:

The strtod() function converts the string pointed to by ptr to double representation. The function recognizes a string containing the following:

The conversion ends at the first unrecognized character. A pointer to that character will be stored in the object to which endptr points if endptr is not NULL.

Returns:

The strtod() function returns the converted value. If the correct value would cause overflow, plus or minus HUGE_VAL is returned according to the sign, and errno is set to ERANGE. If the correct value would cause underflow, then zero is returned, and errno is set to ERANGE.

Zero is returned when the input string cannot be converted. When an error has occurred, errno contains a value indicating the type of error that has been detected.

See also:

atof(), errno

Examples:

#include <stdio.h>
#include <stdlib.h>

void main()
  {
    double pi;

    pi = strtod( "3.141592653589793", NULL );
    printf( "pi=%17.15f\n",pi );
  }

Classification:

ANSI

Systems:

Math