Strange calculation problem
I have a very strange problem. I am multiplying quantity by amount to get a sub total and for most quantities it works ok but for some reason when I enter 5 in the quantity I get a sub total with around 8 decimal places eg 2.99*5 gives me ($14.950000000000001), multiplied by4 gives me $11.96. This also happens on quantity 10,20,30 and so on.
Here is the function:
function totalord()
{
var totitems
var itm1 = document.form1.hambqty.value
var itm2 = document.form1.cheeseqty.value
var itm3 = document.form1.chickqty.value
var itm4 = document.form1.friesqty.value
var itm5 = document.form1.gravyq.value
var itm6 = document.form1.chilliq.value
totitems = eval(itm1+itm2+itm3+itm4+itm5+itm6)
alert("Item 1 is " + itm1)
if (totitems == "0")
{
alert("you have not orderd any items, please enter at least one item(s)")
}
document.form1.hambsub.value = eval(document.form1.hambprice.value.substring(1,6) *itm1)
document.form1.hambsub.value =("$"+document.form1.hambsub.value)
alert("Subtotal 1 is " + document.form1.hambsub.value)
}
|