0
Difficulties on opertions with variables
why haven't we got the good result of 49.5 and why. 49.50000000001 ? https://code.sololearn.com/cDgIcb6DegBY/?ref=app
5 Answers
+ 3
You can use printf() method for formatting floating numbers.
System.out.printf("%.2f",var2);
+ 1
floats and double cannot be precise, because of their binary representation. It often leads to this type of errors, due to floating point precision.
+ 1
It's due to Rounding Error.
+ 1
1.1 can't be represented as a binary decimal number.
+ 1
Thank you Theophile, Soheil, Magat Sam and Seb TheS!!!