RAD Studio |  |

atof, _wtof

Header File

stdlib.h, math.h

Category

Conversion Routines, Math Routines

Prototype

double atof(const char *s);

double _wtof(const wchar_t *s);

Description

Converts a string to a floating-point number.

- atof converts a string pointed to by s to double; this function recognizes the character representation of a floating-point number, made up of the following:
- An optional string of tabs and spaces
- An optional sign
- A string of digits and an optional decimal point (the digits can be on both sides of the decimal point)
- An optional e or E followed by an optional signed integer

The characters must match this generic format:

[whitespace] [sign] [ddd] [.] [ddd] [e|E[sign]ddd]

atof also recognizes +INF and -INF for plus and minus infinity, and +NAN and -NAN for not-a-number.

In this function, the first unrecognized character ends the conversion.

The functions strtod and _strtold are similar to atof and provide better error detection, and hence are preferred in some applications.

Return Value

Returns the converted value of the input string.

If there is an overflow, atof returns plus or minus HUGE_VAL (or _LHUGE_VAL), errno is set to ERANGE (Result out of range), and _matherr (or _matherrl) is not called.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!