C examples for stdlib.h:strtold
function
<cstdlib> <stdlib.h>
Convert string to long double and returns its value as a long double.
long double strtold (const char* str, char** endptr);
Parameter | Description |
---|---|
str | C string representation of a floating-point number. |
endptr | type char* set by the function to the next character in str after the numerical value. |
On success, the function returns the converted floating point number as a value of type long double.
For non valid conversion, the function returns zero (0.0L).
For out of the range values, a positive or negative HUGE_VALL is returned, and errno is set to ERANGE.
#include <stdio.h> #include <stdlib.h> int main ()// www . j a v a 2 s . c o m { char str[] = "1234.305 12345.24 test"; char * pEnd; long double f1, f2; f1 = strtold (str, &pEnd); f2 = strtold (pEnd, NULL); printf ("%Lf\n", f1); printf ("%Lf\n", f2); return 0; }