Hi,
I need to "cast" a double precision to just two decimal places.
For example, if I have a precision 1.114688, I want to turn this to 1.11.
BUT not permanently, just for compare cases.
The problem is actually comparing two numbers, and I only want an estimate. When I write
if(a==b)
then it always gives false, since with that high precision a will never be equal to b. But I am very sure they are equal at two decimal places. And again, I only want the change to be permanent, taking effect only during the if conditional.
I know that I can
printf("0.2%lf" , a);
But that applies to the printf function and I don't know whether you can readily use it freely in other cases as well.
Thank you!
I need to "cast" a double precision to just two decimal places.
For example, if I have a precision 1.114688, I want to turn this to 1.11.
BUT not permanently, just for compare cases.
The problem is actually comparing two numbers, and I only want an estimate. When I write
if(a==b)
then it always gives false, since with that high precision a will never be equal to b. But I am very sure they are equal at two decimal places. And again, I only want the change to be permanent, taking effect only during the if conditional.
I know that I can
printf("0.2%lf" , a);
But that applies to the printf function and I don't know whether you can readily use it freely in other cases as well.
Thank you!
Comment