Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

atof - Convert a string into a floating-point number (double)

&pagelevel(4)&pagelevel

Definition

#include <stdlib.h>

double atof(const char *s);

atof converts a string to which s points into a floating-point number of type double. The string to be converted may be formatted as follows:

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

All control characters for white space are legal for tab (see definition of white space under isspace).

Return val.

Floating-point number of type double



for strings formatted as described above and representing a numeric value that is within the permissible floating-point range.


0

for strings which do not correspond to the syntax described above.


HUGE_VAL

for strings whose numeric value lies outside the permissible floating-point range. In addition, errno is set to ERANGE (result too large).

Notes

The decimal point (or comma) in the string to be converted is affected by the locale (category LC_NUMERIC). The decimal point is the default.

atof also recognizes strings that begin with digits but then end with any character: it cuts off the numeric part, converts it according to the above description, and ignores the rest.

Example

The following program converts a string passed in the call (Enter Options) into the
corresponding floating-point number.

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
               /* Numbers are passed as strings!! A conversion is */ 
               /* required if the numeric value is needed */
{
  printf("floating : %f\n", atof(argv[1]));
  return 0;
}

See also

atoi, atol, strtod, strtol, strtoul