• support@answerspoint.com

Convert number into xx.xx million format?

6019

s there a simple way to convert a high number e.g. 14120000 into 14.12 million format with PHP?

I've been looking at number_format but it doesn't seem to offer this function, also thought about sub_str to separate the digits out, but thought there might be a better way?

2Answer


0

This will turn your currency number into presentable format.

function thousandsCurrencyFormat($num) {
  $x = round($num);
  $x_number_format = number_format($x);
  $x_array = explode(',', $x_number_format);
  $x_parts = array('k', 'm', 'b', 't');
  $x_count_parts = count($x_array) - 1;
  $x_display = $x;
  $x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : '');
  $x_display .= $x_parts[$x_count_parts - 1];
  return $x_display;
}

 

  • answered 9 years ago
  • Gul Hafiz

0
<?php
    # Output easy-to-read numbers
   
    function bd_nice_number($n) {
        // first strip any formatting;
        $n = (0+str_replace(",","",$n));
        
        // is this a number?
        if(!is_numeric($n)) return false;
        
        // now filter it;
        if($n>1000000000000) return round(($n/1000000000000),1).' trillion';
        else if($n>1000000000) return round(($n/1000000000),1).' billion';
        else if($n>1000000) return round(($n/1000000),1).' million';
        else if($n>1000) return round(($n/1000),1).' thousand';
        
        return number_format($n);
    }

echo bd_nice_number('14120000'); //14.12 million

?>

 

  • answered 9 years ago
  • Gul Hafiz

Your Answer

    Facebook Share        
       
  • asked 9 years ago
  • viewed 6019 times
  • active 9 years ago

Best Rated Questions