I get the correct results.
I get the correct results even if I use the sprintf with "%f". because sprintf approximate.
The "245.76" string came from a MySQL database. And I need it as a double because I make some calculation.
I have tried to approximate the double value with the function form http://www.experts-exchang
double fprec(double f,int prec)
{
double p = pow(10,prec);
return floor(f*p)/p;
}
But it returns the same thing.
Main Topics
Browse All Topics





by: Infinity08Posted on 2007-01-24 at 03:11:18ID: 18384540
What's the output of this program :
#include <iostream>
int main(void) {
double d = atof("245.76");
std::cout << d << std::endl;
return 0;
}
I get the correct result.
In any case, if you want exact precision, then a double is probably not what you want (it's a floating point number).
What do you need this for ? For certain applications, fixed point could be an option ...