I've googled this a lot but i can't find any helpful functions based on my queries.
What i want is:
100 -> 100
1000 -> 1,000
142840 -> 142,840
BUT
2023150 -> 2.023M ( i still want 3 additional numbers for more accuracy )
5430120215 -> 5.430B
I would totally appreciate any custom functions to dynamically choose the limit if possible.
Thanks!
Works for positives and negatives.
Try this. Accounts for the groups k, M, B, T, and Q (quadrillion). Anything higher than 999Q shows as 999Q+.
Use
number_format()
:If "limit" refers to the number of decimal places (the precision), that's easy:
Altough this question was asked quite some time ago I have a different solution, which I think is even more simple:
I hope that it's still helpful for someone.
CakePHP has a Number Helper with a method
toReadableSize
. You should be able to grok it and come up with something on your own. In it,$this->precision
is basically likenumber_format()
, and__n
is a singular-or-plural function.