andyhajime Posted September 3, 2008 Share Posted September 3, 2008 I have this TEXT FIELD which suppose to accept only numbers. It's actually a field for "price". I manage to find a javascript for accepting only numbers. Now I'm having issue when user keyed in 00030 into the field. When it's being save into the database and displayed out to the website, it's displays as $00030. Is there any function in PHP which I can remove the 3 zeros or any zeros leading before it? Link to comment https://forums.phpfreaks.com/topic/122578-how-to-remove-leading-zero-from-a-number-in-php/ Share on other sites More sharing options...
Mchl Posted September 3, 2008 Share Posted September 3, 2008 Store the prices as DECIMAL type in database. In PHP you can try casting. For integers: $number = (int)$number; For numbers with decimal point $number = (float)$number; although you must be careful with this last one, as floats aren't precise. Link to comment https://forums.phpfreaks.com/topic/122578-how-to-remove-leading-zero-from-a-number-in-php/#findComment-632897 Share on other sites More sharing options...
discomatt Posted September 3, 2008 Share Posted September 3, 2008 If you have a proper column type in your table, the leading zeros will be stripped automatically. Use decimal, float, or integer types. Link to comment https://forums.phpfreaks.com/topic/122578-how-to-remove-leading-zero-from-a-number-in-php/#findComment-632901 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.