0

So I'm wondering what would be the best way to achieve truncate numbers to the highest thousand value in PHP like Facebook, Twitter and else do with their followers counters:

echo shortify(5710); // outputs 5.7K
echo shortify(145236); // outputs 145.2K
echo shortify(14365859); // outputs 14.3M
// and so on

I don't think PHP has a built-in function that handles this problem so I'm willing to know about any script / Git repo / Symfony bundle that would achieve that goal.

I'm pretty sure this question has been asked on SO but, as english is not my native language, I couldn't find out the right keywords to make a proper research. As such, feel free to flag this question as a duplicate of an already-answered one.

Many thanks.

D4V1D
  • 5,805
  • 3
  • 30
  • 65

0 Answers0