Click to See Complete Forum and Search --> : Decimal places in javascript


Conde
07-09-2003, 10:01 AM
Hi I need help, I building a website with an order form where clients can order goods and preview it, before sending their order.

The problem I have is that, I have a javascript function that calculates the goods bought, and gives me a GRAND TOTAL.

But the grand total is comming with so many decimal places, like this: £68.8470450853

What I am asking is if anyone know a piece of code on how to solve this problem. What I want is only two decimal places, like that: £68.84 Thank you if you can help me...

Khalid Ali
07-09-2003, 10:07 AM
var total = 68.8470450853;
you can use
Number.toFixed(2) where param 2 will force 2 decimap point values to be allowed.

alert(total.toFixed(2) will result this
68.84

pyro
07-09-2003, 10:19 AM
Just one small correction. the toFixed property will round the decimal places, so in the above example, it would return 68.85

Khalid Ali
07-09-2003, 10:24 AM
Whenever I am in wisconsin I'll make you watch Jim Carey movies....I think thats the most appropriate punnishement..:D

pyro
07-09-2003, 10:28 AM
lol... I love Jim Carrey movies... :p

Khalid Ali
07-09-2003, 10:30 AM
damn,,,,,well I 'll keep working on it..;)