maggiemay654
05-02-2003, 11:28 PM
Hello,
Is there a way to make the following script round to the nearest .10 on the cents? I often get totals like: 95.08000000000001.
<SCRIPT LANGUAGE="JavaScript">
<!-- // Begins
function CalculateTotal(frm)
{
var total=0, price, qty, fld, nam;
for (var i=0; i < frm.elements.length; ++i)
{
fld = frm.elements[i];
nam = fld.name;
if (nam.substring(0,4) == "item")
{
price = unescape(nam.substring(nam.indexOf("_",5) + 1, nam.length));
qty = unescape(fld.value);
if (qty > 0) total = total + (qty * price);
}
frm.TOTAL.value = total;
}
// Ends -->
</SCRIPT>
Thank you!! :D
Is there a way to make the following script round to the nearest .10 on the cents? I often get totals like: 95.08000000000001.
<SCRIPT LANGUAGE="JavaScript">
<!-- // Begins
function CalculateTotal(frm)
{
var total=0, price, qty, fld, nam;
for (var i=0; i < frm.elements.length; ++i)
{
fld = frm.elements[i];
nam = fld.name;
if (nam.substring(0,4) == "item")
{
price = unescape(nam.substring(nam.indexOf("_",5) + 1, nam.length));
qty = unescape(fld.value);
if (qty > 0) total = total + (qty * price);
}
frm.TOTAL.value = total;
}
// Ends -->
</SCRIPT>
Thank you!! :D