PDA

View Full Version : Javascript - text box currency format



riteoh
Mar 26th, 2007, 01:28 AM
Hello,

Firstly - relatively new to javascript.

I have seen many examples of code that will return a passed value in a currency format - however I have a sales form that is calculating values via a function in the text boxes I want formatted with a currency ($) symbol. The function that is called is not passing any values, and returning a calculation of the form subtotals per item, and then total sales figure.

Can anybody give me any hints on format these cells to a currency value?

I can give examples of how my code is currently if required.

Thanks in advance

glenngv
Mar 26th, 2007, 05:31 AM
total = 1.235;
total = "$" + total.toFixed(2);
alert(total); //$1.24

total = 10;
total = "$" + total.toFixed(2);
alert(total); //$10.00

hans_cellc
Oct 4th, 2011, 01:20 PM
Hi this seems like a simple solution and works but will I be able to use the text box in future number calculations.

Philip M
Oct 4th, 2011, 02:44 PM
Hi this seems like a simple solution and works but will I be able to use the text box in future number calculations.

No. .toFixed() returns a string value. Use a separate variable for the displayed value.


total = 1.235;
Gtotal = "$" + total.toFixed(2);
alert(Gtotal); //$1.24

total = 10;
Gtotal = "$" + total.toFixed(2);
alert(Gtotal); //$10.00