Put it in JS somewhere.
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
name it like this: 2 after the number there are now many decimals that you want to round to.
alert(roundNumber( 0.0099999999999909,2));
in your case it will be alert(roundNumber(figure,2));
WORK EXECUTED CODE:
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
$( "#allocate_total_amount_paid" ).click(function() {
var totalAmountPaid = parseFloat($("#total_amount_paid").val());
$( ".amount_received" ).each(function( index ) {
var thisAmount = parseFloat($(this).attr("max"));
if (thisAmount <= totalAmountPaid) {
$(this).val(roundNumber(thisAmount,2)).trigger('input');
totalAmountPaid -= thisAmount;
} else {
$(this).val(roundNumber(totalAmountPaid,2)).trigger('input');
totalAmountPaid = 0;
}
});
});
source
share