Hide the fractional part in a decimal number if it is .00, in PHP

When displaying decimal numbers, it will show both the Integer and Fractional part even if the fractional part is 00. Like below:

  • 2.35
  • 3.50
  • 2.00

If we need to hide the fractional part when it is 0, just add the number with 0 as below:

<?php echo $amount + 0; ?>

This makes PHP show the fractional part only if it is non-zero, as below:

  • 2.35
  • 3.50
  • 2

Leave a Comment