Something like this:
echo somefn(2800000000); // outputs '2,8B' for 2,8 billion
echo somefn(2000000); // outputs '2M' for 2 million
echo somefn(5400); // outputs '5,4K' for 5,400
echo somefn('blabla') // outputs 'blabla' as it is because it isn't a number
echo somefn(5) // outputs 5, nothing to simplify
I know it must be really easy code but I wonder if anyone else has something that accounts for maybe other cases that don’t pop in my head right now.
/Edit I’m looking for something more in the lines of a generalized, built-in PHP function (or something close to that). Pretty much the same way strtotime() can handle things like “weeks” or “months”.
I don’t know of any off the shelf function you can call. Here’s one possible solution: