6.23.49 wcstod Function
Convert wide string to a double precision floating-point value.
Include
<wchar.h>
Prototype
double wcstod(const wchar_t * restrict nptr, wchar_t ** restrict
endptr);
Arguments
nptr- the wide string to attempt to convert
endptr- pointer to store the address of the remainder of the wide string that was not converted
Return Value
The converted value, or 0 if the conversion could not be performed. If the correct value of
the conversion is outside the range of representable values, HUGE_VAL is
returned with a sign being that of the correct value. If the result underflows, the function
returns a value whose magnitude is no greater than the smallest normalized positive number in
the return type.
Remarks
The wcstod function attempts to convert a portion of the wide string pointed
to by nptr to a double floating-point value.
The initial section consists of any white-space wide characters.
- Decimal digits optionally
containing a decimal-point wide character, then an optional exponent part,
being
eorEfollowed by an option sign and decimal digits - A
0xor0X, then a nonempty sequence of hexadecimal digits optionally containing a decimal-point wide character, then an optional binary exponent part, beingporP, and option sign, and decimal digits. - one of
INForINFINITY, ignoring case NAN, ignoring case, optionally followed by any sequence contain digits or non-digits:
endptr, provided that
endptr is not a null pointer.The final section consists of wide characters in the wide string that were
unrecognized in the subject section and which will include the terminating null wide
character of the wide string. This section of the wide string will be accessible via
the address stored to endptr, provided endptr is
not a null pointer.
The value of the macro ERANGE is stored in errno if
the correct value of the conversion is outside the range of representable values.
The errno variable is not set to ERANGE if the
result underflows.
Example
#include <wchar.h>
int main(void)
{
wchar_t ws[] = L"2000.5 -6.0E-3 0x70FF INFINITY";
wchar_t * pEnd;
double d1, d2, d3, d4;
d1 = wcstod(ws, &pEnd);
d2 = wcstod(pEnd, &pEnd);
d3 = wcstod(pEnd, &pEnd);
d4 = wcstod(pEnd, NULL);
wprintf(L"The converted string values are: %g, %g, %g, and %g.\n", d1, d2, d3, d4);
}
Example Output
The converted string values are: 2000.5, -0.006, 28927, and inf.
