Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Biology Forums - elokuu 05, 2014, 02:21:35 IP

Otsikko: How to shorten numbers across the forum to K/M/B?
Kirjoitti: Biology Forums - elokuu 05, 2014, 02:21:35 IP

1372 -> 1.3 K
2023150 -> 2 M
5430120215 -> 5.4 B


I found this solution: http://stackoverflow.com/questions/4371059/shorten-long-numbers-to-k-m-b/4371114#4371114

How could I incorporate that into SMF?
Otsikko: Re: How to shorten numbers across the forum to K/M/B?
Kirjoitti: Matthew K. - elokuu 05, 2014, 02:38:24 IP
As I mentioned on Google Chat - in case anyone else is interested in the answer that I provided. You would need to specify where exactly you would want to incorporate this, there isn't a viable method to convert all numbers into formats as such.
Otsikko: Re: How to shorten numbers across the forum to K/M/B?
Kirjoitti: Arantor - elokuu 05, 2014, 02:41:23 IP
Because comma_format totally isn't a thing that would be the ideal place to do this.
Otsikko: Re: How to shorten numbers across the forum to K/M/B?
Kirjoitti: margarett - elokuu 05, 2014, 02:42:15 IP
Tricky...
It depends really on where that comes from. Inside posts should be difficult, maybe using a custom BBC for it, but that also requires you to add BBC tags around the numbers you want to "shorten".
Outside the posts you can hack "function comma_format" --> Subs.php but I can't really tell if this is used everywhere...

edit: ninja'd :P
Otsikko: Re: How to shorten numbers across the forum to K/M/B?
Kirjoitti: Arantor - elokuu 05, 2014, 02:43:02 IP
It's used everywhere that's actually important because it's what also does number formatting, in a manner that doesn't depend on setlocale settings.
Otsikko: Re: How to shorten numbers across the forum to K/M/B?
Kirjoitti: Biology Forums - elokuu 05, 2014, 02:46:57 IP
So, can this be done via the comma_format function?
Otsikko: Re: How to shorten numbers across the forum to K/M/B?
Kirjoitti: Arantor - elokuu 05, 2014, 02:47:35 IP
With a non trivial rewrite of it, sure.