Figuring Different Amounts [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Figuring Different Amounts [Resolved]

Post 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.
Last edited by Epiales on Sun Sep 29, 2013 10:01 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: Figuring Different Amounts

Post by Winawer »

Can't you just remove the ifs/elseifs you don't need?
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Figuring Different Amounts [Resolved]

Post 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!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”