PHP - replace character

0 votes
211 views
added Sep 24, 2019 in PHP by lcjr First Warrant Officer (11,790 points)
//Replace digit of 100,000 with K,M or B
<?php
if(!empty($project['avg_price'])) {
  $digit = $project['avg_price'];
  if ($digit >= 1000000000) {
      $digit =  round($digit/ 1000000000, 1). 'B';
  }
  if ($digit >= 1000000) {
      $digit =  round($digit/ 1000000, 1).'M';
  }
  if ($digit >= 1000) {
      $digit =  round($digit/ 1000, 1). 'K';
  }
  $project['avg_price'] = $digit;
}
?>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...