When I add two numbers together I get Calculation error like that:
0.1 + 0.2 = 0.30000000000000004
Can I solve this problem without rounding the result?
When I add two numbers together I get Calculation error like that:
0.1 + 0.2 = 0.30000000000000004
Can I solve this problem without rounding the result?
In short: No. Try googeling floating point arithmetic. That should answer all your questions.
https://0.30000000000000004.com/
You also could use something different from Double
, like BigDecimal
:
BigDecimal.valueOf(0.1) + BigDecimal.valueOf(0.2)