i'm stuck trying to have all numbers shown with only 2 decimals and adding the , for numbers 1,000 plus. how can i do this?
<SCRIPT LANGUAGE="JavaScript">
<!--
function roundoff(amount) {
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
function total(what,number) {
var grandTotal = 0;
var yearTotal = 0;
for (var i=0;i<number;i++) {
if (what.elements['price' + i].value == '')
what.elements['price' + i].value = '0.00'; // fix for Opera.
what.elements['subtotal' + i].value=(what.elements['quantity' + i].value - 0) * (what.elements['price' + i].value - 0);
if (what.elements['quantity' + i].value == "0")
what.elements['subtotal' + i].value = "0.00";
subtotal=what.elements['subtotal' + i].value
grandTotal += (what.elements['price' + i].value - 0) * (what.elements['quantity' + i].value - 0);
}
subtotal=roundoff(Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2));
what.grandTotal.value = roundoff(Math.round(grandTotal*Math.pow(10,2))/Math.pow(10,2));
what.elements['yearTotal'].value=(what.elements['grandTotal'].value - 0) * (12);
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
function roundoff(amount) {
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
function total(what,number) {
var grandTotal = 0;
var yearTotal = 0;
for (var i=0;i<number;i++) {
if (what.elements['price' + i].value == '')
what.elements['price' + i].value = '0.00'; // fix for Opera.
what.elements['subtotal' + i].value=(what.elements['quantity' + i].value - 0) * (what.elements['price' + i].value - 0);
if (what.elements['quantity' + i].value == "0")
what.elements['subtotal' + i].value = "0.00";
subtotal=what.elements['subtotal' + i].value
grandTotal += (what.elements['price' + i].value - 0) * (what.elements['quantity' + i].value - 0);
}
subtotal=roundoff(Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2));
what.grandTotal.value = roundoff(Math.round(grandTotal*Math.pow(10,2))/Math.pow(10,2));
what.elements['yearTotal'].value=(what.elements['grandTotal'].value - 0) * (12);
}
//-->
</SCRIPT>
Comment