Hi,
I need to keep a number with a 5 digit percision. for some reason when I keep the number 99.99999 in a double, the actual number kept is 99.98999995.
I want to round the number to its 5th precision point.
Any ideas how to do that?
Thanks,
RMOK
Hi,
I need to keep a number with a 5 digit percision. for some reason when I keep the number 99.99999 in a double, the actual number kept is 99.98999995.
I want to round the number to its 5th precision point.
Any ideas how to do that?
Thanks,
RMOK
It is usual that the float (or double) contains values that differ from the value it should have contained. Look herethe actual number kept is 99.98999995.
Maybe you could do something like:want to round the number to its 5th precision point.
Code:double ADouble=99.24689657; double RoundResult=round(ADouble*(double)1e3)/(double)1e3;
Last edited by MathFan; 06-06-2005 at 06:22 AM.
The OS requirements were Windows Vista Ultimate or better, so we used Linux.
Won't setprecision() help?
cout<<setprecesion(5)<<float_variable; //Is'nt this right?
Well, that is right, but that is if you do not want to change variable's value. In your example you set precision of OUTPUT values pushed through iostream. And that won't change the variable itself.cout<<setprecesion(5)<<float_variable;
Last edited by MathFan; 06-06-2005 at 06:24 AM.
The OS requirements were Windows Vista Ultimate or better, so we used Linux.