In Eiffel, after doing some operations on a value of type DOUBLE
, I get the result 1.9999999999999998
, while the expected result is supposed to be 2
.
I know that this is caused due to inaccuracies in floating point arithmetic. I need only two digits of precision (while using the DOUBLE
type), and hence, if the number could be rounded off to two digits, I think the result would be 2
as expected.
I have seen this question, but it only talks about displaying two digits, while I would like to know if there is a way to round off and store the value with two digits of precision.
Thank you.