strtod

Converts a string to double representation

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:String Conversion

Syntax

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

Parameters

ptr
(IN) Points to the string to be converted.
endptr
(OUT) Points to the first unrecognized character.

Return Values

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.

Remarks

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

  • Optional white space
  • An optional plus (+) or minus (-) sign
  • A sequence of digits containing an optional decimal point
  • An optional e or E followed by an optionally signed sequence of digits

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.

See Also

atof

Example

  #include <limits.h>  
  #include <stdlib.h>  
   
  double convert_pi ()  
  {  
     double pi;  
     pi = strtod ("3.141592653589793", NULL)  
     return (pi);  
  }