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~ 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.? 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. 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. 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. 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. 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
Archived
This topic is now archived and is closed to further replies.