Compartir a través de


strtod, wcstod (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Convert strings to a double-precision value.

double wcstod( const wchar_t *nptr, wchar_t **endptr);

Parameters

  • nptr
    Null-terminated string to convert.
  • endptr
    Pointer to character that stops scan.

Return Values

wcstod returns the value of the floating-point number, except when the representation would cause an overflow, in which case the function returns +/–HUGE_VAL. The sign of HUGE_VAL matches the sign of the value that cannot be represented. wcstod returns 0 if no conversion can be performed or an underflow occurs.

Remarks

These functions are supported by all versions of the C run-time libraries.

The wcstod function converts nptr to a double-precision value. wcstod stops reading the string nptr at the first character it cannot recognize as part of a number. This may be the terminating null character.

The following table shows generic-text routine mappings for this function.

TCHAR.H Routine _UNICODE Defined
_tcstod wcstod

For more information about TCHAR.H routines, see Generic Text Mappings.

The LC_NUMERIC category setting of the current locale determines recognition of the radix character in nptr.

If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr.

If no conversion can be performed (no valid digits were found or an invalid base was specified), the value of nptr is stored at the location pointed to by endptr.

wcstod expects nptr to point to a string of the following form:

[whitespace] [sign] [digits] [.digits] [ {d | D | e | E}[sign]digits]

A whitespace can consist of space and tab characters, which are ignored; sign is either plus (+) or minus (–); and digits are one or more decimal digits.

If no digits appear before the radix character, at least one must appear after the radix character. The decimal digits can be followed by an exponent, which consists of an introductory letter (d, D, e, or E) and an optionally signed integer.

If neither an exponent part nor a radix character appears, a radix character is assumed to follow the last digit in the string. The first character that does not fit this form stops the scan.

Example

Description

This program uses strtod to convert a string to a double-precision value; strtol to convert a string to long integer values; and strtoul to convert a string to unsigned long-integer values.

Code

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
   char   *string, *stopstring;
   double x;
   long   l;
   int    base;
   unsigned long ul;
   string = "3.1415926This stopped it";
   x = strtod( string, &stopstring );
   printf( "string = %s\n", string );
   printf("   strtod = %f\n", x );
   printf("   Stopped scan at: %s\n\n", stopstring );
   string = "-10110134932This stopped it";
   l = strtol( string, &stopstring, 10 );
   printf( "string = %s", string );
   printf("   strtol = %ld", l );
   printf("   Stopped scan at: %s", stopstring );
   string = "10110134932";
   printf( "string = %s\n", string );
   /* Convert string using base 2, 4, and 8: */
   for( base = 2; base <= 8; base *= 2 )
   {
      /* Convert the string: */
      ul = strtoul( string, &stopstring, base );
      printf( "   strtol = %ld (base %d)\n", ul, base );
      printf( "   Stopped scan at: %s\n", stopstring );
   }
}
// Output
string = 3.1415926This stopped it
   strtod = 3.141593
   Stopped scan at: This stopped it

string = -10110134932This stopped it   strtol = -2147483647   Stopped scan at: This stopped itstring = 10110134932
   strtol = 45 (base 2)
   Stopped scan at: 34932
   strtol = 4423 (base 4)
   Stopped scan at: 4932
   strtol = 2134108 (base 8)
   Stopped scan at: 932

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdio.h, string.h.

Link Library: coredll.dll.

See Also

atof

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.