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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.