Keil Logo

atof

Summary
#include <stdlib.h>

double atof (
  const unsigned char *string);   /* string to convert */
Description

The atof function converts string into a floating-point value. The input string must be a sequence of characters that can be interpreted as a floating-point number. This function stops processing characters from string at the first one it cannot recognize as part of the number.

The string passed to atof must have the following format:

〚{+|-}〛 digits.digits 〚{e|E} 〚{+|-}〛 digits

Where

digits

May be one or more decimal digits (0-9).
Return Value

The atof function returns the floating-point value produced by interpreting the characters in string as a number.

If no conversion could be performed, NaN (not a number) is returned.

See Also

atoi, atol

Example
#include <stdlib.h>
#include <stdio.h> /* for printf */

void tst_atof (void) {
  float f;
  char s [] = "1.23";

  f = atof (s);
  printf ("ATOF(%s) = %f\n", s, f);
}
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.