samedi 7 mars 2015

Java Math unexpected trailing decimal



Currently learning Java, can anyone explain why the following code yields this output?



System.out.println(330*1.1);


363.00000000000006


When it should simply equal 363. Why is there the trailing decimal?


Alternatively, the following code correctly outputs 363.0 yet is mathematically equivalent.



double check = 330;
check = check + check*0.1;
System.out.println(check);



Aucun commentaire:

Enregistrer un commentaire