Number formatting

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Number formatting

Post by imkingdavid »

If you look right now at a high number in phpBB, (e.g. 10000, 1000, etc.), it is all one flat string. I think that changing this would be a good idea for 3.1, as numbers that have comma separation are easier to read at a glance. What I mean is changing 10000 to 10,000.

Take 1000000000 for example. While I realize that unlikeliness of that number occurring on a forum any time soon, it works well in this example. So looking at it, can you quickly tell me how many zeros there are? Probably not, since they all seem to run together. Well, I've done the hard part and counted it for you: there are 9 zeros. So let's add a comma in every three. Ok, here's the number: 1,000,000,000 (aka 1 billion). Much easier to read at a glance, in my opinion.

A simple remedy, which I have successfully implemented on my site, is to use the number_format() PHP function, which automatically adds the comma, decimal, etc. every three digit (taking decimals into consideration as well). Of course, I realize that some people are used to decimals where others are used to commas, and vice-versa, so possibly adding a setting for the user to decide which to use or if to use it at all would be a good idea.

By the way, in the language file, %d will need to be changed to %s or else it will stop the number at the comma, so 1,500 would become 1 because it will be truncated at the comma.

I got this information from here. In all, I think it would be helpful for 3.1, or even 3.0.8 (wishful thinking).
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: Number formatting

Post by EXreaction »

Which numbers are you talking about?

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: Number formatting

Post by imkingdavid »

Well, for instance go to the forum index here on area51. See the "Total redirects: 162737" (or similar)? Instead, it should read "162,737".

Or scroll down some and see the Topics/Posts stats per forum, which are in the thousands or even then thousands. Those should also have commas.

And in the statistics area with the total topics, total posts, and total members. Those should have commas.

Shall I continue? ;)
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: Number formatting

Post by MichaelC »

I think this would be a good feature for big forums ect.,
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

User avatar
DarkBeing
Registered User
Posts: 83
Joined: Sun Jul 19, 2009 2:32 pm
Location: Currently Estonia
Contact:

Re: Number formatting

Post by DarkBeing »

In general I like the idea. The problem is not all languages use the comma as the separator the same way. I.e. 3500 this way converted to 3,500 would for you mean in words three thousand five hundred. For me that would say three and one half with the two zeros just being placeholders. For me you would have to use the "." to have the same effect. 3.500 instead of 3,500. There is probably a way to have that covered, but not sure if it would be worth the effort.

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: Number formatting

Post by MichaelC »

DarkBeing wrote:In general I like the idea. The problem is not all languages use the comma as the separator the same way. I.e. 3500 this way converted to 3,500 would for you mean in words three thousand five hundred. For me that would say three and one half with the two zeros just being placeholders. For me you would have to use the "." to have the same effect. 3.500 instead of 3,500. There is probably a way to have that covered, but not sure if it would be worth the effort.
Yeah, to cover multi-lanuages it would mean numbers would have there own language file. But every single number in existence would need to be recorded in it twice, one as the variable, one as the the one with/without the comma.

Although I'm not 100% sure but it could possibly be done with IF statements but then each language pack installed would need to have a result for the IF meaning language packs would need to make edits in files in the /includes/ file.

Great idea and it would be great if it was implemented. But for the result I think its probably to complicated to code.
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

idiotnesia
Registered User
Posts: 29
Joined: Thu May 22, 2008 2:46 am

Re: Number formatting

Post by idiotnesia »

the number_format() PHP function support for localization. In language pack, thousand separator need to add.
idiotnesia wuz here

ToonArmy
Registered User
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK
Contact:

Re: Number formatting

Post by ToonArmy »

idiotnesia wrote:the number_format() PHP function support for localization. In language pack, thousand separator need to add.
That's fine if the number is separated at the thousands but that's not always followed. Another consideration is I actually prefer the SI standard of space for a thousands separator over the standard comma in English. See http://en.wikipedia.org/wiki/Decimal_se ... t_grouping
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image

igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: Number formatting

Post by igorw »

If such a system were implemented it should be handled by the language system. There is already some capability for similar things in user::lang(). Allowing the language pack to specify places for this formatting to be used would seem like a good way to do this.

User avatar
bantu
3.0 Release Manager
3.0 Release Manager
Posts: 557
Joined: Thu Sep 07, 2006 11:22 am
Location: Karlsruhe, Germany
Contact:

Re: Number formatting

Post by bantu »

eviL3 wrote:If such a system were implemented it should be handled by the language system. There is already some capability for similar things in user::lang(). Allowing the language pack to specify places for this formatting to be used would seem like a good way to do this.
I'd like to suggest something similar.

I generally agree that the user should be able to specify the format, either by the language pack or by manually selecting the format. Most operating systems also allow you to change the format. The current way of showing large numbers is certainly better than a hardcoded format because for some it's 3,500.50 USD, for others it's 3.500,50 EUR ;-) (which has been mentioned already).

It might be a good idea to have most of the formats in the phpBB core itself (I guess there are just a few), so one would be able to select the format he/she wants even if the corresponding language pack is not installed. I agree that the language pack should specify a default format and the user setting should be "Use what the language pack says" by default.

Post Reply