![]() |
![]() |
![]() |
Convert a string to a double
#include <wchar.h> double wcstod( const wchar_t * ptr, wchar_t ** endptr ); float wcstof( const wchar_t * ptr, wchar ** endptr ); long double wcstold( const wchar_t * ptr, wchar ** endptr );
libc
These functions convert a string to a number: The wcstod() function converts the string pointed to by ptr to double representation; wcstof() converts to a float; wcstold() to a long double. The function recognizes a string containing the following:
The function expects the subject to have a plus or minus sign followed by one of these forms:
The value is correctly rounded if the subject is hexadecimal and FLT_RADIX is 2.
The radix character is locale specific, depending upon LC_NUMERIC.
The conversion ends at the first unrecognized character. If endptr isn't NULL, a pointer to the unrecognized wide character is stored in the object endptr points to.
![]() |
Because 0 is a valid return that is also used for an error, errno should be set to 0 before calling these functions, then checked again afterward. These functions don't change errno on success. |
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.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
"String manipulation functions" and "Wide-character functions" in the summary of functions chapter.
![]() |
![]() |
![]() |