0

Why 170.5546/.0001 is 1705545.999999 but 170.5543/.0001 is 1705543 in java script, this thing I run ob browse.

In java script the / behavior is different, I tried in browser but not able to conclude it. The behavior is different when I am calculating in calculator and Java

Prakash4U
  • 1
  • 1
  • Read about floating point precision. p.s. If you try to evaluate 170.5546/0.0001 in Java, those are doubles with higher precision. Try 170.5546f/0.0001f in Java and you will see the same thing as in JS. – Silviu Burcea May 17 '23 at 12:11
  • "_The behavior is different when I am calculating in calculator and Java_" - No, you will get the same result in Java. – Ivar May 17 '23 at 12:13
  • @Ivar unless the numbers are doubles, which have different precision. – Silviu Burcea May 17 '23 at 12:15
  • @SilviuBurcea Numbers in JavaScript also have double floating point precision. `System.out.println(170.5546/.0001)` yields `1705545.9999999998`. (Using any/both as floats of course gives a different result.) – Ivar May 17 '23 at 12:18

0 Answers0