Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string to float conversion?

Tags:

c++

c

I'm wondering what sort of algorithm could be used to take something like "4.72" into a float data type, equal to

float x = 4.72;
like image 527
jmasterx Avatar asked Mar 10 '26 03:03

jmasterx


1 Answers

scanf, operator>> for istreams, and strtof would be the obvious choices.

There is also atof, but, like atoi, it lacks a way to tell you there was an error in the input, so it's generally best to avoid both.

like image 138
Jerry Coffin Avatar answered Mar 12 '26 18:03

Jerry Coffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!