---
name: "atof"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/atof/3"
---

# atof(3)

convert ASCII string to double

## NAME

**atof**, **atof\_l** – convert ASCII string to double

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<stdlib.h\>**

*double*\

**atof**(*const char \*str*);

**#include \<xlocale.h\>**

*double*\

**atof\_l**(*const char \*str*, *locale\_t loc*);

## DESCRIPTION

The **atof**() function converts the initial portion of the string pointed to by *str* to *double* representation.

It is equivalent to:

```
strtod(str, (char **)NULL);
```

The decimal point character is defined in the program's locale (category LC\_NUMERIC).

While the **atof**() function uses the current locale, the **atof\_l**() function may be passed a locale directly. See [xlocale(3)](/xlocale/3.md) for more information.

## IMPLEMENTATION NOTES

The **atof**() and **atof\_l**() functions are thread-safe and async-cancel-safe.

The **strtod**() and  **strtod\_l**() functions are recommended instead of  **atof**() and **atof\_l**() functions, especially in new code.

## ERRORS

The function **atof**() need not affect the value of *errno* on an error.

## SEE ALSO

[atoi(3)](/atoi/3.md), [atol(3)](/atol/3.md), [strtod(3)](/strtod/3.md), [strtol(3)](/strtol/3.md), [strtoul(3)](/strtoul/3.md), [xlocale(3)](/xlocale/3.md)

## STANDARDS

The **atof**() function conforms to ISO/IEC 9945-1:1990 (“POSIX.1”), ISO/IEC 9899:1990 (“ISO C90”), and ISO/IEC 9899:1999 (“ISO C99”).
