Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round & Limit Decimal Places in Calculated Result 1

Status
Not open for further replies.

megp

Programmer
Aug 25, 2004
31
US
I use the following script to calculate the total amount due based on the amount ("invoice") entered in the form ("pay"). All works as needed, except that I need to be able to limit the results to two decimal places, preferably rounded as needed. What am I missing?

Thank you,
Meghan

Code:
<script language="JavaScript">
function doTotals()
{
var x = document.forms['pay'].elements['invoice'].value;
var z = ((x*1.029)+(0.3))
document.forms['pay'].elements['amount'].value = z;
}
</script>
 
Missing this:

Code:
var z = ((x*1.029)+(0.3))[!].toFixed(2)[/!];

<.

 
If you also want this rounded, preferrably down, you can do this:

Code:
var z = Math.floor((x*1.029)+(0.3) * 100) / 100;


<.

 
Hey, megp, how about clicking on the link that says "Thank monksnake for this valuable post!" since he helped you?

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top