strtod

Converts a string to double-precision value.

Library:LibC
Classification:ANSI
Service:General C Services

Syntax

  #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

If successful, returns the converted value. Otherwise, returns one of the following:

  • If the correct value causes overflow, returns plus or minus HUGE_VAL and sets errno to ERANGE. The sign of HUGE_VAL matches the sign of the value that cannot be represented.

  • If the correct value causes underflow, returns 0 and sets errno to ERANGE.

  • If the input string cannot be converted, returns 0 and sets errno to EINVAL.

Remarks

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

  • Optional whitespace characters

  • 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

strtol