Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strtod, strtof, strtold - convert string to double-precision number

&pagelevel(4)&pagelevel

Definition

#include <stdlib.h>

double strtod(const char *s, char **endptr);
float strtof(const char *s, char **endptr);
long double strtold(const char *s, char **endptr);

Description

These functions convert the string to which s points into a floating-point number of type double. The string to be converted may be structured as follows:

[{ tab |'BLANK'}...][+|-][ digit ...][.][ digit ...][{E|e}[+|-] digit ...]
or
[{ tab |'BLANK'}...][+|-]0{X|x}[ hexdigit ...][.][ hexdigit ...][{P|p}[+|-] digit ...]

Any white-space character may be used for tab (see definition under isspace()).

strtod() also recognizes strings that start with a digit but end with some other character.
In such cases, strtod() first truncates the numeric part and converts it to a floating-point value.

strtod() returns a pointer (*endptr) to the first non-convertible character in string s via the second argument endptr of type char **, but only if endptr is not passed as a null pointer.

If endptr is a null pointer, strtod() is executed like the atof() function:

atof(s) is equivalent to strtod(s, (char **)NULL) and strtod(s, NULL).

If endptr is not a null pointer, a pointer (*endptr) to the first character in s that completes the conversion is returned. If absolutely no conversion is possible, *endptr will be set to the start address of string s.

Return val.

Floating-point number of type double, float or long double



for strings which are structured as described above and represent a numeric value within the permissible floating-point range.


0

for strings that do not conform to the syntax described above or do not begin with convertible characters.


+/-HUGE_VAL
+/-HUGE_VALF
+/-HUGE_VALL

depending on the function type and the sign of x, for strings whose numeric value lies outside the permissible floating-point range. errno is set to indicate the error.

Errors

strtod() will fail if:

 

ERANGE

The return value causes an overflow or underflow

 

EINVAL

No conversion could be performed.

Notes

The radix character in the string to be converted is determined by LC_NUMERIC category of the locale. The default is a period. 

See also

atof(), atoi(), atol(), isspace(), strtol(), strtoul(), stdlib.h.