Formatting numerical output
How do I go about applying formatting to the result of a numerical calculation in a Javascript form?
ie - I want 150000 to display as $150,000
The $ is easy enough, I can apply that outside the output field but how could I get the comma in there?
.....
Suzanne posted this at 22:00 — 30th April 2002.
She has: 5,507 posts
Joined: Feb 2000
http://javascript.internet.com/forms/currency-format.html
Whoo! Google rocks. Man. That wasn't the top result, but it was the fourth unique site for javascript+money -- it would probably be first for javascript+currency.
Anyway, lol, hope that helps.
taff posted this at 23:39 — 30th April 2002.
They have: 956 posts
Joined: Jun 2001
ooh boy. That's gonna be tough for a scripting bonehead like me to graft onto the existing script. I've got about a dozen results to apply this to
Thanks for finding it though. I thought that there might be a simple property that I wasn't aware of.
.....
Suzanne posted this at 00:20 — 1st May 2002.
She has: 5,507 posts
Joined: Feb 2000
It's a function, so you would add it around the other functions.
If your result is dosomething(input,input,input), then you would do this:
currencyfunction(dosomething(input,input,input))
Of course, it's a little bit more complex than this, but not too much. Post a link to a sample of your code and I'm sure that someone (maybe even me!) can help you integrate it.
taff posted this at 15:04 — 2nd May 2002.
They have: 956 posts
Joined: Jun 2001
Trial and error is a wonderful thing!
I got it to work - thanks Suzanne.
Suzanne posted this at 01:13 — 3rd May 2002.
She has: 5,507 posts
Joined: Feb 2000
Yay! Well done, then.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.