Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
755 views
in Q2A Core by
If a user has 1000 points, this gets displayed as 1,000 points.

In most non English-speaking countries the comma (,) is used to indicate decimals. So 1,000 points is considered to be 1 point.

I would like to use a point (.) instead in this case, so it reads "1.000". Is this possible? If not, can this be added to the core.
Q2A version: 1.7.0-beta-1

3 Answers

+2 votes
by

Currently I see that the php function responsible for formatting the numbers is used with only one input parameter, that is in the form :

number_format($points)

(see for instance the code of the users.php )

In this case the PHP uses always the comma as a thousands separator :

If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.

I think that a possible solution should be that of modifying the core (sigh, it looks like an externally -and globally- set LC_NUMERIC isn't read by the format_number) and replacing the occurrences of number_format (with input parameter the "user's points") with a version that accepts as an additional parameter the thousands separator too :

string number_format ( float $number , int $decimals = 0 , string $dec_point = "," , string $thousands_sep = "." )

that is, considering as an example the users.php ( which corresponds to the page with the users' list : http://www.yourq2asite.com/users ), changing

from :

'score' => qa_html(number_format($user['points'])),

to :

'score' => qa_html(number_format($user['points'],0,',','.')),

and so on for all the other occurrences (favorites.php , user-profile.php , qa-theme.php , etc etc ...).

Not a very nice solution frown (you have to modify multiple files of the core....), however it should work.

ps

The above solution should be tested for any side effects too.... wink

 

0 votes
by

I have this question for years, don't ask me why I never asked or solved it. Therefore: big thanks for bringing up the issue.

IMO there should be an admin option to specify the decimal sign 0,01 or 0.01 and the separator for thousands 1.000 or 1,000 or 1 000 (empty too).

Attempt without core hack:

1. Create a layer plugin or use the advanced theme, i.e. edit the file qa-theme.php

2. Points are output in the user nav and in the user meta, and users pages, so we should catch those from the $this->content:

3. e.g. override the head script like that:

function head_script(){
            qa_html_theme_base::head_script();
            // access points from $content, change commas to dots of logged in user
            var_dump($this->content['raw']['account']['points']);
            var_dump($this->content['raw']['points']['points']);
}

BREAK

Unfortunately, as I see now, maxjtechno is right. The value cannot be overriden. It is indeed set by the core.

WORKAROUND:

Use Jquery: FIND all points occurences by its class names, and string-replace the char '.' with ','.

 

I really hope Scott can fix this. I reported the issue at github.

+3 votes
by
I've been working on this recently and modified all needed files from 1.7.0 with this feature. I've added a way to customize the thousand separators, decimal points and the ability to compact numbers, e.g., user reputation can be displayed like 12.3k instead of 12,364. You can either use the branch or take the changes and apply them or customize them the way you want from here: https://github.com/pupi1985/question2answer/tree/patch-48 (use the download zip) button
...