Jump to content

Budget calculator Math Round


yoyo
 Share

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; }}

Link to comment
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""

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...