I am well aware that 0.1+0.2 != 0.3
because of precision errors. However I need it to be equal to 0.3.
My solution would be to :
- Declare an
add
function that returns the correctdouble
. - Inside this function, add the two numbers then round to the 13th digit.
This would work for 0.49999999999999994 and 0.30000000000000004.
How would I implement such a rounding function? Is there another way?