0

My code:

$(document).ready(function() {

    var num1 = 1473.735;
    var num2 = 1473;

    var num3 = num1 - num2;

    alert(num3); // 0.7349999999999
}

Javascript seems to round my numbers very strangely.

How is it possible that javascript comes up with a strange decimal notation with such a simple calculation?

1473.735 - 1473 = 0.735, and not 0.7349999999999.

Here my Sandbox example: https://codepen.io/thomasveld/pen/yLebMMo

thanks in advance.

ThomasV
  • 346
  • 3
  • 16
  • 1
    can you show, how you're calculating these values, or where they are from? – korki Jun 23 '20 at 08:32
  • I've changed the code. I just set simple numeric values. I'm using the FormatMoney, but it rounds numbers down. So I did this simple calculation to see what happens. And javascript seems to calculate things differently. – ThomasV Jun 23 '20 at 08:38
  • 1
    @ThomasV See the duplicate link on top of your question. That should explain things. – Ivar Jun 23 '20 at 08:45

0 Answers0