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

add 2 numbers and force only 2 decimal places

Status
Not open for further replies.

oshjosh

Technical User
Mar 11, 2002
34
0
0
TH
Hi

Thanks for the replies to my last post, I have another small script problem. I am using the script below to add 2 numbers

<script>document.write(24.99+2.99);</script>

when I add some numbers such as the ones in the example I get about 12 numbers after the decimal point, how can I force this to only show 2 decimal numbers?

Thanks in advance

Rob
 

Try this:

Code:
<script>document.write( ((24.99*100) + (2.99*100)) / 100 );</script>

Hope this helps,
Dan

 
Dan

Thanks once again worked like a dream.. I am learning slowly

Cheers
Rob
 
This decimal stuff is a popular topic these days!

--Dave
 
Hmmm... It would be my first. Let's see what today holds in store!

Thanks for the idea!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top