Wednesday, February 2, 2011

LOCALE_SDECIMAL LOCALE_IDIGITS

LOCALE_SDECIMAL


Character(s) used for the decimal separator, for example, "." in "3.14" or "," in "3,14". The maximum number of characters allowed for this string is four, including a terminating null character.

LOCALE_IDIGITS


Number of fractional digits placed after the decimal separator. The maximum number of characters allowed for this string is two, including a terminating null character. For example, 2 for 5.00, 1 for 5.0.

strtod, wcstod

Convert string to double

Convert strings to a double-precision value.


double strtod(  const char *nptr,   char **endptr );

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

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

Return Value
strtod 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. strtod returns 0 if no conversion can be performed or an underflow occurs.

wcstod returns values analogously to strtod. For both functions, errno is set to ERANGE if overflow or underflow occurs.

Remarks

Each function converts the input string nptr to a double. The strtod function converts nptr to a double-precision value. strtod stops reading the string nptr at the first character it cannot recognize as part of a number. This may be the terminating null character. wcstod is a wide-character version of strtod; 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
_tcstod                    |                 strtod                                    |       strtod             |          wcstod

The LC_NUMERIC category setting of the current locale determines recognition of the radix character in nptr; for more information, see setlocale. 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.

strtod 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

strtod   and wcstod or


Example:
/* strtod example */

#include
#include

int main ()
{
char szOrbits[] = "365.24 29.53";
char * pEnd;
double d1, d2;

d1 = strtod (szOrbits,&pEnd);
d2 = strtod (pEnd,NULL);

printf ("The moon completes %.2lf orbits per Earth year.\n", d1/d2);
return 0;
}

Output:

The moon completes 12.37 orbits per Earth year.

atof Convert string to double (function)

strtol Convert string to long integer (function)
strtoul Convert string to unsigned long integer (function)

Convert string to double with two decimal precision C++







No comments:

Post a Comment

Health Benefits of Cashews

  Benefits of Cashews. Healthy food is an integral part of healthy body. Regular exercises such as Yoga and healthy diet is important to...