![]() |
![]() |
![]() |
Convert a string to a double
#include <stdlib.h> double strtod( const char *ptr, char **endptr );
libc
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. If endptr isn't NULL, a pointer to the unrecognized character is stored in the object endptr points to.
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 can't be converted. When an error occurs, errno indicates the error detected.
#include <stdio.h> #include <stdlib.h> int main( void ) { double pi; pi = strtod( "3.141592653589793", NULL ); printf( "pi=%17.15f\n",pi ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
![]() |
![]() |
![]() |