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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.