is there any function like atoi() but convert the string to a float number??
is there any function like atoi() but convert the string to a float number??
but what if my string = "2219.5851"??
as atof(string) = 2219.59.......
how can i get the exact float number??
For this you may want to use one of the scanf functions. Such as sscanf(string, "%.3g", &my_float).
[edit]
Oops, I didn't read that correctly.
The return is probably correct, floats are perfect, and it is possible that printf is the one doing the rounding.
[/edit]
Last edited by master5001; 03-14-2003 at 03:12 AM.
mmmmm i use cout to print the output....
but the number also rounded.....
and see the examples in MSDN........seems the result are rounded too......
strtod()
Check the FAQ for using strtol() which is the long int version of this function, you can base your code on those examples.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Originally posted by Jasonymk
mmmmm i use cout to print the output....
but the number also rounded.....
and see the examples in MSDN........seems the result are rounded too......Code:#include <iostream> // std::cout, std::endl #include <iomanip> // std::setprecision int main() { double d = 1234.56789; std::cout << d << std::endl; // output: 1234.57; std::cout << std::setprecision(10) << d << std::endl; // output 1234.56789 return 0; }