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

joaomachado’s picture

Issue summary: View changes

typo..

Deciphered’s picture

Issue summary: View changes
Status: Active » Fixed

You would need to create a PHP formatter with either the code in the function, or passing the field items through the function.

E.g.,

return nice_number($items[0]['value']);

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.