0

I was trying to solve math expression, but java or python sums to double numbers incorrectly

Ex: 1.2 - 0.3 = 0.9 but the code solves it as 1.2 - 0.3 = 0.8999999999999999 Why does it happening and how can i solve it (wasn't able to find out in google)

JAVA version :

java 11.0.5 2019-10-15 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)

The code in JAVA

public class Main {
    public static void main(String[] args) {

        System.out.println(
                1.2 - 0.3
        );

    }
}

The result is


0.8999999999999999

on Python


print(1.2 - 0.3)

the result is

0.8999999999999999
Asylzat
  • 197
  • 5
  • 17

0 Answers0