Jump to content

How to remove leading zero from a number in PHP?


andyhajime

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.