I use atof() in a function but i get stranges values..
when converted I get the following:
what is wrong here? atof() itself?
string temp_num = "";
char dot = '.';
while ((isdigit(temp_string[n])) || (temp_string[n] == dot))
temp_num += temp_string[n++];
number_value = atof(temp_num.c_str());
I also tried atol() but it wouldnt convert to decimal?
I know someone else asked the same question but using a correction factor in my case wont solve my problem.. :(
"...but i get stranges values"
I don't see any strange values. Where are they?
"what is wrong here?"
"I also tried atol() but it wouldnt convert to decimal?"
Maybe that's why they hit upon the function name "alpha to long"?
You aren't going to get an exact representation of a base 10 number using base 2 which computers use. However, within about 10 decimal places, they are exact.
Yep, floats aren't perfect. You are either going to have to find some way to deal with that, or use doubles.