Possible Duplicate:
JavaScript: formatting number with exactly two decimals
Maybe I'm going about this the wrong way, but I have some javascript which is filling up some text inputs with numbers like 12.434234234. I want the text input to only display 12.43, but I'd like it's value to remain as 12.434234234.
Is this even possible? If not, what would be the best work-around?
Thanks! John.
--
Although there were some very good answers here, I was looking for something like 'why don't you just use this clever one liner thing..' - hence I've ticked the most basic approach which is to just use an extra field. Thanks though! Marked up all answers.
num = 12.434234234;
result = num.toFixed(2); // returns 12.43
You can store the fine-grained values in hidden fields, and trim the ones displayed for the user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With