Skip to content Skip to sidebar Skip to footer

Calculate A Minus Operation In Javascript Returns A Incorrect Value

This is my javascript code : var dsum = 0.0; $.each($('#Report tbody tr'), function () { var x = 0.0; if ($(this).find('td:eq(3) div').html() != ' ') x =

Solution 1:

It happens because it works with convertions from binary to decimal, then we have aproximations, whose result on big floating numbers. See:

var i = 1;//1
i += .1;//1.1
i += .1;//1.2000000000000002

You can try an own aproximation:

var result = Math.round((1318114.01-1213225)*1000)/1000;

Post a Comment for "Calculate A Minus Operation In Javascript Returns A Incorrect Value"