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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decimal Places 1

Status
Not open for further replies.

pastorandy

IS-IT--Management
Nov 2, 2006
84
GB
I have the following that calculates and displays the result in an html input form field called payment_amount

Code:
  <input type="button" class="input-calc" name="plus2" value="Calculate Deposit"
  onClick="document.calc2.payment_amount.value = 
  parseFloat((document.calc2.total_cost.value) - parseFloat(document.calc2.discount_given.value))* 0.3">

What I can't seem to do is to format the output to only 2 decimal places. Any advice?
 
Use the round() function.

Code:
onClick="document.calc2.payment_amount.value =
  [red]math.round([/red][green]parseFloat((document.calc2.total_cost.value) - parseFloat(document.calc2.discount_given.value))* 0.3[/green][red]);[/red]">



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Sorry, its [red]M[/red]ath.round, upper case M.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top