PHPProgramming

Remove all Zero From the number PHP

In this blog we will learn about how we can remove the last zero from the number, there are various way to remove the zero from the number.

I will show you the easiest way to remove zero from the number using php.

To remove Last zero from number using PHP

$number = 9900;
$removezero = $number/100;
echo $removezero; 
//output
99

Show number in the decimal format

If you want to convert the number in decimal format for example if you have numbers like 9900, 13400 and you want to convert it to 99.00 and 134.00 then use the below code.

$stripefee = 9900
$amount = $stripefee/100;
$stringAmount = "$amount";
echo number_format((float)$stringAmount, 2, '.', '');

//output
99.00

Remove trailing Zero or First Zero from the number using PHP

There are many ways to remove trailing Zero from the number, I will show you the easiest way to remove all the first Zero or trailing zero from the number in PHP.

// Store the number string with 
// leading zeros into variable
$str = "00087456";

// Passing the string as first 
// argument and the character 
// to be removed as second 
// parameter 
$str = ltrim($str, "0");  

// Display the result 
echo $str; 

//output
87456

Now I will show another way to remove trailing zero from the number using PHP.

// Store the number string with 
// leading zeros into variable 
$str = "00087456"; 
 
// First typecast to int and  
// then to string 
$str = (string)((int)($str)); 
 
// Display the result 
echo $str; 

//output
87456

Read Also: PHP Ajax Jquert Post Example in PHP

I hope you like the above article, any confusion feel free to comment.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button