function
<cwchar>
wcstod
double wcstod (const wchar_t* str, wchar_t** endptr);
Convert wide string to double
Parses the C wide string str interpreting its content as a floating point number and returns its value as a double. If endptr is not a null pointer, the function also sets the value of endptr to point to the first character after the number.
This is the wide character equivalent of strtod (<cstdlib>), interpreting str in the same way.
Parameters
- str
- C wide string beginning with the representation of a floating-point number.
- endptr
- Reference to an already allocated object of type wchar_t*, whose value is set by the function to the next character in str after the numerical value.
This parameter can also be a null pointer, in which case it is not used by the function.
Return Value
On success, the function returns the converted floating point number as a value of type double.
If no valid conversion could be performed, the function returns zero (0.0).
If the correct value is out of the range of representable values for the type, a positive or negative HUGE_VAL is returned, and errno is set to ERANGE.
If the correct value would cause underflow, the function returns a value whose magnitude is no greater than the smallest normalized positive number (some library implementations may also set errno to ERANGE in this case).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13
|
/* wcstod example */
#include <wchar.h>
int main ()
{
wchar_t szOrbits[] = L"365.24 29.53";
wchar_t * pEnd;
double d1, d2;
d1 = wcstod (szOrbits,&pEnd);
d2 = wcstod (pEnd,NULL);
wprintf (L"The moon completes %.2f orbits per Earth year.\n", d1/d2);
return 0;
}
| |
Output:
The moon completes 12.37 orbits per Earth year.
|
See also
- strtod
- Convert string to double (function
)
- wcstol
- Convert wide string to long integer (function
)
- wcstoul
- Convert wide string to unsigned long integer (function
)