atof
double atof ( const char * string ); | math.h stdlib.h |
cplusplus.com |
Convert string to double.
Parses string interpreting its content as a floating point number and
returns a value of type double.
Parameters.
Return Value.
The converted floating point value of the input string.
On overflow the result is undefined.
If an error occurs 0.0 is returned.
Portability.
Defined in ANSI-C.
Example.
/* atof example: sines calculator */
#include <stdio.h>
#include <math.h>
main ()
{
double n,m;
double pi=3.1415926535;
char szInput [256];
printf ( "Enter degrees: " );
gets ( szInput );
n = atof ( szInput );
m = sin (n*pi/180);
printf ( "sine of %f degrees is %f\n" , n, m );
return 0;
}
Output:
Enter degrees: 45
sine of 45.000000 degrees is 0.707101
See also.
cstdlib/strtod