问题
I have a few modifications I need for my cost calculator:
Is there a way to add a Math.celi to the no of cans so it rounds up to the nearest whole number, providing the minimum cans needed?
What ever the minimum required cans are, can the cost reflect that by multiplying by 18.23 and giving the real amount?
$('input').keyup(function () { // run anytime the value changes var firstValue = parseFloat($('#width').val()); // get value of field var secondValue = parseFloat($('#height').val()); var thirdValue = parseFloat($('#per-can').val()); // convert it to a float var forthValue = parseFloat($('#cost').val()); var fithValue = parseFloat($('#size').val()); var canCount = firstValue * secondValue / thirdValue; $('#added').html((canCount * forthValue).toFixed(2)); $('#cans').html(canCount.toFixed(2)); if (Math.ceil(canCount) < 2) { $('#error').html("Need at least 1!"); } else { $('#error').empty(); } });
http://jsfiddle.net/5xzSy/504/ thanks
来源:https://stackoverflow.com/questions/25803495/roundup-total-and-multiply-again-jquery-calculator