Search code examples
scalanumbersadditionoperation

There is a сalculation error during addition of two numbers in Scala


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?


Solution

  • In short: No. Try googeling floating point arithmetic. That should answer all your questions.

    https://0.30000000000000004.com/

    "Floating point is broken" duplicates

    https://floating-point-gui.de/