atof()Prototype: float atof(const char *string);Header File: stdlib.h (C) or cstdlib (C++) Explanation: This function accepts a string and converts it into a floating point number. For example, if "1234.34" is passed into the function, it will return 1234.34. If the string contains a decimal place, the number will not be truncated. If a valid number is contained in the string, but is terminated by a non-valid character, the number will be returned, and the non-valid character will be ignored Example: //Example reads in a string, and converts it to an float #include <cstdlib> #include <iostream> using namespace std; int main() { char a_char[10]; cin>>a_char; cout<<"As a float: "<<atof(a_char); }Other Functions |