Answer the question
In order to leave comments, you need to log in
How in Java to store the result of division 1/3, so that when the result is subsequently used, there will be no rounding error?
To make it clearer, let me show you an example. In the standard windows calculator, when you divide 1 by 3, you get the result 0.3333333, when you then multiply this result by 3 again, you get 1. How can I implement this? If you use the rounded result, then there will be an error of 0.3333333*3=0.9999999.
Answer the question
In order to leave comments, you need to log in
When writing the answer, write instead of equal to - approximately, this will not be considered an error!)
0.333333*3≈10
As an option - remember not the last result, but the entire expression. And return the result 1/3*3:
>>>print "%f"%(1/3*3)
1.0000
Added. Now I checked - even if the result of dividing 1.0 by 3.0 is written into a variable, and then this variable is multiplied by 3, it will be 1.0000.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question