Name

atof - convert a string to a double

Library

libc.lib

Synopsis

  #include <stdlib.h>
  double atof (const char *nptr);

Return values

The atof function returns the converted value if the value can be represented.

Detailed description

The atof function converts the initial portion of the string pointed to by nptr to double representation.

It is equivalent to:

strtod(nptr, (char **)NULL);

         

The decimal point character is defined in the program’s locale (category LC_NUMERIC).


Examples

#include <stdlib.h>
#include <stdio.h>
 
void main( void )
{
 /* Test of atof */
 double d = atof("  86778E-2");
 
 printf( "result of atof: %f\n", d );
}

         

Output

result of atof: 867.78

         

Implementation notes

The atof function is not thread-safe and also not async-cancel-safe.

The atof function has been deprecated by strtod and its use is not preferred.


Errors

No errors are defined.

See also

atoi, atol, strtod, strtol, strtoul

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top