I have a really simple jquery code:
$('#monthly_percent').change(function () {
// (2/100*70*30) = 42.00000000000001
$monthly = $('#daily_objective').val()/100*$(this).val()*30;
if($monthly > 0)
$('#monthly_objective').val($monthly);
});
The code is working just fine unless the value of $monthly
becomes 42, in which case it returns decimals.
So if $('#daily_objective').val()
is 2 and $(this).val()
is 70, it returns 42.00000000000001
.
At the end it is just a matter of transforming the value to an integer, but why does this happen, and why does this happen only when the answer is 42?
I tried a bunch of other numbers but it worked fine.