Hi,
I am trying to set decimal value in currency field, but i keep breaking the script.
This is the current script, i have tried to insert .toFixed(2)
$(function() { $(document).ready(function () { function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } function sumtotal() { var s = 0; var s1 = 0; var s2 = 0; var s3 = 0; $('.cf-table-block tbody tr').each(function () { s += parseNumber($(this).find('.estc1 input').val()); s1 += parseNumber($(this).find('.estc2 input').val()); s2 += parseNumber($(this).find('.estc3 input').val()); s3 += parseNumber($(this).find('.estc4 input').val()); }); $('.total input').val(s + s1 + s2 +s3); } $('.cf-table-block').change(sumtotal); }); });
Also tried to enter
s = s.toFixed(2); s1 = s1.toFixed(2); s2 = s2.toFixed(2); s3 = s3.toFixed(2);
and the same for the total. What am i doing wrong?