Syntax
#include <wchar.h> double wcstod(const wchar_t *nptr, wchar_t **endptr);Description
wcstod converts the wide-character string pointed to by nptr to a double value. The nptr parameter points to a sequence of characters that can be interpreted as a numerical value of type double. wcstod stops reading the string at the first character that it cannot recognize as part of a number. This character can be the wchar_t null character at the end of the string.
wcstod expects nptr to point to a string with the following form:
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ >>──┬─────────────┬──┬───┬──┬───────────────────────────┬──>
│
│ └─white-space─┘ ├─+─┤ ├─digits──┬───┬──┬────────┬─┤ │
│ └─┴─┘ │ └─.─┘ └─digits─┘ │ │
│ └─.──digits─────────────────┘ │
│ │
│ >──┬──────────────────────┬──>< │
│ └─┬─e─┬──┬───┬──digits─┘ │
│ └─E─┘ ├─+─┤ │
│ └─┴─┘ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
Note: The character used for the decimal point (shown as . in the above diagram) depends on the LC_NUMERIC category of the current locale.
The white space character is determined by the LC_CTYPE category of the current locale.
wcstod function returns the converted double value. If no conversion could be performed, wcstod returns 0. If the correct value is outside the range of representable values, wcstod returns +HUGE_VAL or -HUGE_VAL (according to the sign of the value), and sets errno to ERANGE. If the correct value would cause underflow, wcstod returns 0 and sets errno to ERANGE.
If the string nptr points to is empty or does not have the expected form, no conversion is performed, and the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer.
This example uses wcstod to convert the string wcs to a floating-point value.
#include <stdio.h> #include <wchar.h> int main(void) { wchar_t *wcs = L"3.1415926This stopped it"; wchar_t *stopwcs; printf("wcs = \"%ls\"\n", wcs); printf(" wcstod = %f\n", wcstod(wcs, &stopwcs)); printf(" Stop scanning at \"%ls\"\n", stopwcs); return 0; /**************************************************************************** The output should be similar to : wcs = "3.1415926This stopped it" wcstod = 3.141593 Stop scanning at "This stopped it" ****************************************************************************/ }Related Information