Hi!
I have a function that automatically updates a field on my form after doing calculations. I only want two numbers after the decimal place.
<!--FUNCTION TO CALCULATE THE TOTAL AMOUNT-->
<script language="javascript">
function calctotal()
{
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvMisc = parseFloat(document.forms['ordersnewform'].elements['OrderMisc'].value-0);
lvUnitPrice1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice1'].value-0);
lvUnitPrice2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice2'].value-0);
lvUnitPrice3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice3'].value-0);
lvUnitPrice4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice4'].value-0);
lvQuantity1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity1'].value-0);
lvQuantity2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity2'].value-0);
lvQuantity3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity3'].value-0);
lvQuantity4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity4'].value-0);
lvUnit1 = lvUnitPrice1 * lvQuantity1
lvUnit2 = lvUnitPrice2 * lvQuantity2
lvUnit3 = lvUnitPrice3 * lvQuantity3
lvUnit4 = lvUnitPrice4 * lvQuantity4
lvTotal = lvShip + lvMisc + lvUnit1 + lvUnit2 + lvUnit3 + lvUnit4;
document.forms['ordersnewform'].elements['OrderTotals'].value = lvTotal;
return true;
}
</script>
RESULTS -
ex- 11*11.20 I will get displayed 123.19999999999999
I want 123.19 or even 123.20 would be better.
THANKS!
I have a function that automatically updates a field on my form after doing calculations. I only want two numbers after the decimal place.
<!--FUNCTION TO CALCULATE THE TOTAL AMOUNT-->
<script language="javascript">
function calctotal()
{
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvShip = parseFloat(document.forms['ordersnewform'].elements['OrderShipping'].value-0);
lvMisc = parseFloat(document.forms['ordersnewform'].elements['OrderMisc'].value-0);
lvUnitPrice1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice1'].value-0);
lvUnitPrice2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice2'].value-0);
lvUnitPrice3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice3'].value-0);
lvUnitPrice4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderUnitPrice4'].value-0);
lvQuantity1 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity1'].value-0);
lvQuantity2 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity2'].value-0);
lvQuantity3 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity3'].value-0);
lvQuantity4 = parseFloat(document.forms['ordersnewform'].elements['SubOrderQuantity4'].value-0);
lvUnit1 = lvUnitPrice1 * lvQuantity1
lvUnit2 = lvUnitPrice2 * lvQuantity2
lvUnit3 = lvUnitPrice3 * lvQuantity3
lvUnit4 = lvUnitPrice4 * lvQuantity4
lvTotal = lvShip + lvMisc + lvUnit1 + lvUnit2 + lvUnit3 + lvUnit4;
document.forms['ordersnewform'].elements['OrderTotals'].value = lvTotal;
return true;
}
</script>
RESULTS -
ex- 11*11.20 I will get displayed 123.19999999999999
I want 123.19 or even 123.20 would be better.
THANKS!