I have a time sheet form and i need to calculate the total hours.
I'm using the 24 hour format to work out the total hours. which works ok, what i need to do is display the total as single digits or double digits , eg 4 or 12 hours is there a way to do this with JavaScript ?
$(document).ready(function () { $('.cf-table-block').on('blur', 'input', sumtotal); function sumtotal() { var hour = 0; var rate = 0; var total = 0; var subtotal = 0; $('.cf-table-block tbody tr').each(function () { hour = parseNumber($(this).find('.hour input').val()); rate = parseNumber($(this).find('.rate input').val()); subtotal = (hour - rate); $(this).find('.total input').val(subtotal); total += subtotal; }); $('.Grandtotal input').val(total); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } });