Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How can I get the following code to work with this module? It does exactly what I what it to do, which is basically take a long number and reduce it to a rounded number that is easier to read.
<?php
function 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),2).' trillion';
else if($n>1000000000) return round(($n/1000000000),2).' billion';
else if($n>1000000) return round(($n/1000000),2).' million';
else if($n>1000) return round(($n/1000),2).' thousand';
return number_format($n);
}
echo nice_number('14120000'); //14.12 million
?>
Source of code: http://stackoverflow.com/questions/10221694/convert-number-into-xx-xx-mi...
Comments
Comment #0.0
joaomachado CreditAttribution: joaomachado commentedtypo..
Comment #1
Deciphered CreditAttribution: Deciphered commentedYou would need to create a PHP formatter with either the code in the function, or passing the field items through the function.
E.g.,