Budget calculator Math Round

Recommended Posts

I have a budget calculator which calculates how much you can afford to take out on a loan. Basically the user inputs a total monthly income and the expenses are deducted.I would like to times the subtotal by .4 everything works fine. But I am getting numbers which are to long. So I have tried to use Math Round but it doesn't work.Could someone please show me how to get this workingThank you function budget(field,theform){ if (! isNumeric(field.value)) { alert("Illegal characters. Please enter numeric values only."); field.value = ""; field.focus(); } theform.subtotal.value = 0; theform.subtotal.value = theform.food.value*1 - theform.rent.value*1 - theform.car.value*1 - theform.savings.value*1; { theform.thetotal.value.Math.round = 0; theform.thetotal.value = theform.subtotal.value*.4; }}

Share on other sites

var x = .4var y= 33.37alert( x * y) // shows "13.347999999999999"alert( (x * y).toFixed(2) ) // shows "13.35"alert( (x * y).toFixed(4) ) // shows "13.3480"alert( parseInt(x * y) ) // shows "13"// if you need to support IE5, netscape nav 4 :var ending = String(x * y).split(".")alert( ending[0] + "." + ending[1].slice(0,2) ) // shows "13.34""

Share on other sites

Thank you for the fast replyI can seem to incorporate the var into my scriptcould you spell it out for mecheers

Share on other sites

I don't know what you're trying to do here:theform.thetotal.value.Math.round = 0;but this is how you use Math.round:theform.thetotal.value = Math.round(theform.subtotal.value*.4);