Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

like atoi but to float

Tags:

c++

casting

atoi

Is there a function similar to atoi which converts a string to float instead of to integer?

like image 233
lital maatuk Avatar asked Feb 16 '11 13:02

lital maatuk


People also ask

Can atoi convert string to float?

The atof() function converts a character string to a double-precision floating-point value. The input string is a sequence of characters that can be interpreted as a numeric value of the specified return type.

What can I use instead of atoi?

So you can replace atoi() with strtol(nptr, NULL, 10) everywhere. As for improving error checking, see the documentation of strtol and what it returns upon different errors.

What is the difference between atoi and atof?

atof recognizes an optional string of tabs and spaces, then an optional sign, then a string of digits optionally containg a decimal point, then an optional e or E followed by an optionally signed integer. atoi recognizes an optional string of tabs and spaces, then an optional sign, then a string of digits.

What is the difference between atoi and stoi?

First, atoi() converts C strings (null-terminated character arrays) to an integer, while stoi() converts the C++ string to an integer. Second, the atoi() function will silently fail if the string is not convertible to an int , while the stoi() function will simply throw an exception.


1 Answers

atof()

(or std::atof() talking C++ - thanks jons34yp)

like image 117
RED SOFT ADAIR Avatar answered Sep 19 '22 13:09

RED SOFT ADAIR