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

Remove decimal with PHP

+1 vote
28 views
added Mar 19, 2018 in PHP by LC Marshal Captain (23,720 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 (23,720 points)

To remove decimal after add comma 

<div class="transaction-item transaction-price">
<?php
  $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>
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...