I have the following code. Works great, except that I want the final tinstotal variable to be rounded to the nearest 1 (2.04 is rounded to 3, etc.)
$(document).ready(function(){ // Animate logo $('#Logo').hide().fadeIn(800); // Calculation Scripts // Square Metres var output = $('#SquareMetres'), tinoutput = $('#Tins'), priceoutput = $('#Price'); $('input[type="text"]').keyup(function() { var width = parseFloat( $('#width').val()), height = parseFloat( $('#height').val()), result = height * width / 10000, finalresult = result.toFixed(2); if (isNaN(result)) return; output.text(finalresult); // Tins var tinmetres = 32.5, tinprice = 18.23, tinsresult = finalresult / tinmetres; tinstotal = tinsresult.toFixed(2); tinoutput.text(tinstotal); var price = tinstotal * tinprice, totalprice = price.toFixed(2); priceoutput.text('£'+totalprice) }); });
The script is active here in http://andyholmes.me/sitewizard/index.html in the red box below. Hope you guys can help, thanks!
Andy holmes
source share