Partager via


strtold, _strtold_l, wcstold, _wcstold_l

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at strtold, _strtold_l, wcstold, _wcstold_l.

Converts strings to a long double-precision floating-point value.

Syntax

long double strtold(  
   const char *nptr,  
   char **endptr   
);  
long double _strtold_l(  
   const char *nptr,  
   char **endptr,  
   _locale_t locale  
);  
long double wcstold(  
   const wchar_t *nptr,  
   wchar_t **endptr   
);  
long double wcstold_l(  
   const wchar_t *nptr,  
   wchar_t **endptr,  
   _locale_t locale  
);  

Parameters

nptr
Null-terminated string to convert.

endptr
Pointer to the character that stops the scan.

locale
The locale to use.

Return Value

strtold returns the value of the floating-point number as a long double, except when the representation would cause an overflow—in that case, the function returns +/–HUGE_VALL. The sign of HUGE_VALL matches the sign of the value that cannot be represented. strtold returns 0 if no conversion can be performed or an underflow occurs.

wcstold returns values analogously to strtold. For both functions, errno is set to ERANGE if overflow or underflow occurs and the invalid parameter handler is invoked, as described in Parameter Validation.

For more information about return codes, see errno, _doserrno, _sys_errlist, and _sys_nerr.

Remarks

Each function converts the input string nptr to a long double. The strtold function converts nptr to a long double-precision value. strtold 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 wide-character version of strtold is wcstold; its nptr argument is a wide-character string. Otherwise, these functions behave identically.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tcstold strtold strtold wcstold
_tcstold_l _strtold_l _strtold_l _wcstold_l

The LC_NUMERIC category setting of the current locale determines the recognition of the radix character in nptr. For more information, see setlocale, _wsetlocale. The functions without the _l suffix use the current locale; _strtold_l and _wcstold_l are identical to _strtold and _wcstold except that they instead use the locale that's passed in. For more information, see Locale.

If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location that's 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 that's pointed to by endptr.

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

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

A whitespace may 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.

Requirements

Routine Required header
strtold, _strtold_l <stdlib.h>
wcstold, _wcstold_l <stdlib.h> or <wchar.h>

For additional compatibility information, see Compatibility.

Example

// crt_strtold.c  
// Build with: cl /W4 /Tc crt_strtold.c  
// This program uses strtold to convert a  
// string to a long double-precision value.  
  
#include <stdlib.h>  
#include <stdio.h>  
  
int main( void )  
{  
   char *string;  
   char *stopstring;  
   long double x;  
  
   string = "3.1415926535898This stopped it";  
   x = strtold(string, &stopstring);  
   printf("string = %s\n", string);  
   printf("   strtold = %.13Lf\n", x);  
   printf("   Stopped scan at: %s\n\n", stopstring);  
}  
string = 3.1415926535898This stopped it  
   strtold = 3.1415926535898  
   Stopped scan at: This stopped it  
  

.NET Framework Equivalent

System::Convert::ToDouble

See Also

Data Conversion
Floating-Point Support
Interpretation of Multibyte-Character Sequences
Locale
String to Numeric Value Functions
strtod, _strtod_l, wcstod, _wcstod_l
strtol, wcstol, _strtol_l, _wcstol_l
strtoul, _strtoul_l, wcstoul, _wcstoul_l
atof, _atof_l, _wtof, _wtof_l
localeconv
_create_locale, _wcreate_locale
_free_locale