Page 1 of 1

Figuring Different Amounts [Resolved]

Posted: Sun Sep 29, 2013 1:39 am
by Epiales
Hey all, didn't really know what to title this....

But what I need is, let's say that I have 2,500,000 income/gold, or whatever. Instead of it showing that amount the way it is, how would I write it so that it would show it as 2500K? Any Ideas? Thanks!!!

The closest I've gotten is something like this:

Code: Select all


<?php

    function my_number_format($n) {
        $n = (0+str_replace(",","",$n));

        if(!is_numeric($n)) return false;

        if($n>1000000000000) return round(($n/1000000000000),1).' T';
        else if($n>1000000000) return round(($n/1000000000),1).' B';
        else if($n>1000000) return round(($n/1000000),1).' M';
        else if($n>1000) return round(($n/1000),1).' K';

        return number_format($n);
    }
    echo my_number_format($stats['gold']);
?>
With this code, if I have 1,500,292, it outputs: 1.5M, which I guess would work, but thought the other way might be better if I can figure that out.

Re: Figuring Different Amounts

Posted: Sun Sep 29, 2013 8:24 am
by Winawer
Can't you just remove the ifs/elseifs you don't need?

Re: Figuring Different Amounts [Resolved]

Posted: Sun Sep 29, 2013 10:01 am
by Epiales
Winawer wrote:Can't you just remove the ifs/elseifs you don't need?
I just kept it the way it is. It works great, so if it's not broken, no need to fix :lol: :lol: :lol:

Thank you for your help!