Xurion Posted October 2, 2007 Share Posted October 2, 2007 Hi all, I have a text field that contains a number that a user specifies. This number is currency and if the user specifies a value such as 10, upon losing the focus, it should format to 10.00. Is there a simple way to do this with JS? Thanks in advance. Xur~ Quote Link to comment https://forums.phpfreaks.com/topic/71507-simple-formatting-of-text-field-numbers/ Share on other sites More sharing options...
fenway Posted October 2, 2007 Share Posted October 2, 2007 It's a simple onblur event handler... but you do need rounding, etc.? Quote Link to comment https://forums.phpfreaks.com/topic/71507-simple-formatting-of-text-field-numbers/#findComment-360007 Share on other sites More sharing options...
Xurion Posted October 2, 2007 Author Share Posted October 2, 2007 Yeah, it can't be more than 2 decimal places. I was thinking about an onBlur. Quote Link to comment https://forums.phpfreaks.com/topic/71507-simple-formatting-of-text-field-numbers/#findComment-360025 Share on other sites More sharing options...
fenway Posted October 2, 2007 Share Posted October 2, 2007 Yeah, it can't be more than 2 decimal places. I was thinking about an onBlur. That doesn't answer the question. Quote Link to comment https://forums.phpfreaks.com/topic/71507-simple-formatting-of-text-field-numbers/#findComment-360055 Share on other sites More sharing options...
Xurion Posted October 2, 2007 Author Share Posted October 2, 2007 The user will specify their own price so: If they supply 10, the field should display 10.00. If they supply 1.1 it shoud display 1.10. If they supply 1.288 it should display 1.29. Hope this is what you needed. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/71507-simple-formatting-of-text-field-numbers/#findComment-360157 Share on other sites More sharing options...
fenway Posted October 3, 2007 Share Posted October 3, 2007 Well, you can probably get away with Math.round() with the usual * 100, / 100 game. Quote Link to comment https://forums.phpfreaks.com/topic/71507-simple-formatting-of-text-field-numbers/#findComment-360758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.