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 set point 1

Status
Not open for further replies.

Argonto

Technical User
Mar 17, 2011
23
US
Hi, Im trying to get an order form to show values as currency. So a ticket costing 38 dollars is seen as 38.00.



Here is a sample of the code, Any and all help is greatly appreciated.

function calculate(what)
{
what.unmform_Total_Price_all.value =



(what.unmform_Total_TreasureIsland_PriceA.value - 0)
+ (what.unmform_Total_TreasureIsland_PriceB.value - 0)
+ (what.unmform_Total_TreasureIsland_PriceC.value - 0)
}

<TR>
<TD vAlign=top align=middle></TD>
<TD vAlign=top align=middle>
<P align=center><STRONG><FONT style="FONT-SIZE: 12px"><U>Treasure Island</U></FONT></STRONG></P></TD>
<TD align=middle>
<P align=left><U><FONT style="FONT-SIZE: 12px"><STRONG>10/23/11 @ 3:00pm</STRONG></FONT></U>&nbsp;</P></TD>
<TD align=middle>&nbsp;</TD></TR>
<TR>
<TD style="WIDTH: 55px" vAlign=top align=middle><INPUT border=0 value="Price A" readOnly align=middle size=10 name=TreasureIsland_PriceA> </TD>
<TD style="WIDTH: 137px" vAlign=top align=middle><INPUT onkeyup="this.form.unmform_Total_TreasureIsland_PriceA.value = (this.form.unmform_Tix_Requested_TreasureIsland_PriceA.value - 0) * (39.00 - 0);calculate(this.form)" border=0 size=10 name=unmform_Tix_Requested_TreasureIsland_PriceA> </TD>
<TD style="WIDTH: 100px" vAlign=top align=middle>$39.00</TD>
<TD style="WIDTH: 100px" vAlign=top align=middle><INPUT border=0 readOnly size=10 name=unmform_Total_TreasureIsland_PriceA></TD></TR>
<TR>
<TD style="WIDTH: 55px" vAlign=top align=middle><INPUT border=0 value="Price B" readOnly align=middle size=10 name=TreasureIsland_PriceB> </TD>
<TD style="WIDTH: 137px" vAlign=top align=middle><INPUT onkeyup="this.form.unmform_Total_TreasureIsland_PriceB.value =(this.form.unmform_Tix_Requested_TreasureIsland_PriceB.value - 0) * (29.00 - 0);calculate(this.form)" border=0 size=10 name=unmform_Tix_Requested_TreasureIsland_PriceB></TD>
<TD style="WIDTH: 100px" vAlign=top align=middle>$29.00</TD>
<TD style="WIDTH: 100px" vAlign=top align=middle><INPUT border=0 readOnly size=10 name=unmform_Total_TreasureIsland_PriceB></TD></TR>
<TR>
<TD style="WIDTH: 55px" vAlign=top align=middle><INPUT border=0 value="Price C" readOnly align=middle size=10 name=TreasureIsland_PriceC> </TD>
<TD style="WIDTH: 137px" vAlign=top align=middle><INPUT onkeyup="this.form.unmform_Total_TreasureIsland_PriceC.value = (this.form.unmform_Tix_Requested_TreasureIsland_PriceC.value - 0) * (19.00 - 0);calculate(this.form)" border=0 size=10 name=unmform_Tix_Requested_TreasureIsland_PriceC></TD>
<TD style="WIDTH: 100px" vAlign=top align=middle>$19.00</TD>
<TD style="WIDTH: 100px" vAlign=top align=middle><INPUT border=0 readOnly size=10 name=unmform_Total_TreasureIsland_PriceC> <INPUT type=hidden name=unmform_LineBreak6> </TD></TR>
 
Hi

Use the [tt]Number.toString()[/tt] method :
Code:
[blue]>>> 3.141592653589793.toFixed(2)[/blue]
[red]"3.14"[/red]
[blue]>>> 3..toFixed(2)[/blue]
[red]"3.00"[/red]
Note that the result is a string.


Feherke.
 
Thanks for responding, I've fiddled with the .toFixed(2) stuff in the past but i haven't gotten it to work. I'm probably doing something wrong.
Where in the code would i use it?

Thanks
 
Hi

Argonto said:
Where in the code would i use it?
Before displaying the value :
Code:
[b]function[/b] [COLOR=darkgoldenrod]calculate[/color][teal]([/teal]what[teal])[/teal]
[teal]{[/teal]
  what[teal].[/teal]unmform_Total_Price_all[teal].[/teal]value [teal]=[/teal]
    [teal][highlight]([/highlight]([/teal]what[teal].[/teal]unmform_Total_TreasureIsland_PriceA[teal].[/teal]value [teal]-[/teal] [purple]0[/purple][teal])[/teal]
  [teal]+[/teal] [teal]([/teal]what[teal].[/teal]unmform_Total_TreasureIsland_PriceB[teal].[/teal]value [teal]-[/teal] [purple]0[/purple][teal])[/teal]
  [teal]+[/teal] [teal]([/teal]what[teal].[/teal]unmform_Total_TreasureIsland_PriceC[teal].[/teal]value [teal]-[/teal] [purple]0[/purple][teal])[/teal][highlight][teal]).[/teal][COLOR=darkgoldenrod]toFixed[/color][teal]([/teal][purple]2[/purple][teal])[/teal][/highlight]
[teal]}[/teal]

Feherke.
 
Awesome, Thank you very much for your help. My co-workers and i have been trying to find this solution for several days.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top