yoyo Posted February 5, 2008 Share Posted February 5, 2008 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 More sharing options...
rnd me Posted February 5, 2008 Share Posted February 5, 2008 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 More sharing options...
yoyo Posted February 5, 2008 Author Share Posted February 5, 2008 Thank you for the fast replyI can seem to incorporate the var into my scriptcould you spell it out for mecheers Link to comment Share on other sites More sharing options...
yoyo Posted February 5, 2008 Author Share Posted February 5, 2008 i got what i needed from herehttp://javascript.about.com/library/blbudget.htmThank you Link to comment Share on other sites More sharing options...
justsomeguy Posted February 5, 2008 Share Posted February 5, 2008 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); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.