[Previous] [Contents] [Next]

atof()

Convert a string to a double

Synopsis:

#include <stdlib.h>

double atof( const char* ptr );

Library:

libc

Description:

The atof() function converts the string pointed to by ptr to a double. It is equivalent to calling strtod() like this:

strtod( ptr, (char**)NULL )

Returns:

The converted double or 0.0 if an error occurs.

Errors:

If an error occurs, errno is set to ERANGE.

Examples:

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
    double x;

    x = atof( "3.1415926" );
    printf( "x = %f\n", x );
    return EXIT_SUCCESS;
}

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, sscanf(), strtod()


[Previous] [Contents] [Next]