ILE C/C++ Run-Time Library Functions


wcstod() -- Convert Wide-Character String to Double

Format

#include <wchar.h>
double wcstod(const wchar_t *nptr, wchar_t **endptr);

Language Level: XPG4

Threadsafe: Yes.

Description

The wcstod() function converts the initial portion of 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. The wcstod() function 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.

The behavior of the wcstod() function is affected by the LC_CTYPE category of the current locale.

Note:
This function is not available when LOCALETYPE(*CLD) is specified on the compilation command.

If the program is compiled with a UNICODE LOCALETYPE, then the wide characters being converted are assumed to be Unicode characters.

Return Value

The wcstod() function returns the converted double value. If no conversion could be performed, the wcstod() function returns 0. If the correct value is outside the range of representable values, the wcstod() function 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, the wcstod() function 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.

The value of errno may be set to ERANGE, range error.

Example that uses wcstod()

This example uses the wcstod() function 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


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]