Are you first timer at Why not join us and start exchange your programming knowledge with everyone. Register today!

Remove decimal with PHP

+1 vote
added Mar 19, 2018 in PHP by LC Marshal Captain (26,090 points)
edited Mar 27, 2018 by LC Marshal

Instead of :

<div class="prop-rooms"><?php print $field_prop_built_up; ?></div>

Use this:

<div class="prop-rooms"><?php print str_replace(".0","",$field_prop_built_up); //Remove trailing .0 from decimals ?></div>

1 Response

0 votes
responded Mar 27, 2018 by LC Marshal Captain (26,090 points)

To remove decimal after add comma 

<div class="transaction-item transaction-price">
  $lot_size  = $row['area_sqft'];
  $psf  = $row['unit_price_psf'];
  $total_price = $lot_size * $psf; 

  $total_price_comma = number_format($total_price, 2, '.', ',');

<?php print str_replace(".0","",$total_price_comma); ?>
</div> - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.