[Solved] Trim zeros from decimal part php


You can use substr() function also to remove last char if it is 0. May be the below code will help you

function roundit($string)
{
 $string = number_format($string,2);
 if (substr($string, -1, 1) == '0')
 {
  $string = substr($string, 0, -1);
  echo $string;
 }
 else
 echo $string;
}
roundit('150.00');
roundit('150.10');
roundit('150.76');

4

solved Trim zeros from decimal part php