Atof () function in C
The double atof function (const char * str) in Standard C Library converts a string pointed to by parameter str to a floating point number (type double).
The double atof function (const char * str) in Standard C Library converts a string pointed to by parameter str to a floating point number (type double).
Declare atof () function in C
Below is the declaration for the atof () function in C:
double atof ( const char * str )
Parameters
str - This is a string with a representation of a floating point number.
Returns the value
This function returns the floating point number that was converted as a double value. If no valid conversion is performed, it returns 0.0.
For example
The following C program illustrates the usage of the atof () function in C:
#include #include #include int main () { float val ; char str [ 20 ]; strcpy ( str , "98993489" ); val = atof ( str ); printf ( "Gia tri duoi dang chuoi = %s, nGia tri duoi dang so thuc = %fn" , str , val ); strcpy ( str , "QTM.com" ); val = atof ( str ); printf ( "nGia tri duoi dang chuoi = %s, nGia tri duoi dang so thuc = %fn" , str , val ); return ( 0 ); }
Compile and run the above C program to see the results.
According to Tutorialspoint
Last lesson: stdlib.h in C
Next lesson: The function atoi () in C
- DAY function in SQL Server
- MIN function in SQL Server
- MAX function in SQL Server
- SUM function in SQL Server
- The ord () function in Python
- RIGHT function in SQL Server
- Int () function in Python
- AVG function in SQL Server
- 6 Conditional Functions That Make Excel Spreadsheets Smarter
- Hex () function in Python
- ABS function in SQL Server
- SUM for Newbies Only: Excel Experts Use This Function Instead!
- The function id () in Python
- DATEPART function in SQL Server