Mahdi.Pishguy Mahdi.Pishguy - 2 years ago 115
PHP Question

PHP remove last zero from integer by substr

in php i get some values from database as integer, now i want to remove last zero from

integer, but me below code doesnt work.

$payerd_amount = 20000000;
$payerd_amount = substr((string)$payerd_amount,1,strlen((string)$payerd_amount) -1);

how to do this action? my code seems correct but after substring i get this result:


Answer Source

If all you want to do is remove the last zero, just divide by 10

   $payerd_amount = $payerd_amount / 10;

This works, too:

   $payerd_amount = substr($payerd_amount, 0, -1);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download