Thousand separator

Is there a feature that you would like to see added to Enuuk Auction Platform?
Post Reply
bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Thousand separator

Post by bamse » Tue Nov 06, 2012 10:34 pm

class/String.php->printMoney handles the display of bid amounts/price. Among others it can add comma as thousand separator which is fine for many countries including the US and UK. However there are many countries (large parts of Europe, South America) where the role of comma and full stop are reversed, i.e. where the comma separates decimals and the full stop marks thousands. For those countries the comma thousand separator might be confusing.

It would be good if that function could switch between these two conventions based on the language setting. I understand that the convention does not match languages exactly, but it could be an improvement.

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Thousand separator

Post by RWAP » Wed Nov 07, 2012 8:51 am

PHP will automatically change the decimal point to a comma, and a comma thousands separator to a decimal point, dependent on language settings (see setlocale() in PHP references)

There is therefore no need to change the String class.

bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Re: Thousand separator

Post by bamse » Wed Nov 07, 2012 9:24 am

Not sure I understand how that works. Do I need to change something to the code elsewhere or something in the php settings or should it work out of the box?

For the default English version I get the comma as thousand separator. Then I also have a Polish language (pl_PL) of the website, but it still shows the comma (instead of a full stop).

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Thousand separator

Post by RWAP » Wed Nov 07, 2012 9:39 am

It should work out of the box...

It may be a bug in the version of PHP on your machine - try changing the following function in class\Language.php to read:

Code: Select all

    static public function changeLanguage($lang)
    {
        $return = false;
        if(DIRECTORY_SEPARATOR == "/"){ //just for Unix/Linux/MAC... does not really work on Win
            $postfix = array('.utf8', '.UTF8', '.UTF-8', '');
            foreach($postfix as $ext){
               $result = setlocale(LC_ALL, $lang.$ext);
                if($result){
                    $return = true;
                    if(substr($lang, 0, 2) == 'tr'){ //due to a PHP bug with tr_TR
                        setlocale(LC_ALL, 'en_US.utf8');
                        setlocale(LC_MESSAGES, $lang.$ext);
                    }
                    if(substr($lang, 0, 2) == 'pl'){ //due to a PHP bug with pl_PL
                        setlocale(LC_NUMERIC, 'C');
                    }
                    break;
                }
            }
        }
        return $return;
    }

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Thousand separator

Post by RWAP » Wed Nov 07, 2012 9:42 am

You can check whether your version of PHP has a problem by using the following code:

Code: Select all

<?php
if (false !== setlocale(LC_ALL, 'pl_PL.UTF-8')) {
    $locale_info = localeconv();
    print_r($locale_info);
}
?>
This should output something similar to:
Array
(
[decimal_point] => .
[thousands_sep] =>
[int_curr_symbol] => EUR
[currency_symbol] => €
[mon_decimal_point] => ,
[mon_thousands_sep] =>
[positive_sign] =>
[negative_sign] => -
[int_frac_digits] => 2
[frac_digits] => 2
[p_cs_precedes] => 1
[p_sep_by_space] => 1
[n_cs_precedes] => 1
[n_sep_by_space] => 1
[p_sign_posn] => 1
[n_sign_posn] => 2
[grouping] => Array
(
)

[mon_grouping] => Array
(
[0] => 3
[1] => 3
)

)

bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Re: Thousand separator

Post by bamse » Sat Nov 10, 2012 12:41 pm

Thanks for the reply, but somehow it still does not work. I tried the php test you posted and no problems there.

Also added the lines you suggest to class/Language.php->changeLanguage() but without success. Not sure why I would want 'C' locale there!?

Now I got really confused, just to make sure: The locale is set when the user clicks on the interl-anguage links in the header, correct? It is not the locale that the user has installed on his computer, correct?

BTW, I see the same problem in the demo version:

http://www.enuuk.com/enuuk-auction-platform/?lang=es_ES

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Thousand separator

Post by RWAP » Sat Nov 10, 2012 2:33 pm

Ah - I see the problem, I don't recall fixing this for my websites, but I obviously did at some point...

In class\String.php find:

Code: Select all

        if($siteOption['thousandsSeparator']){
            $amount = number_format($amount,$decimalDigits,'.',',');
        }else{
            $amount = number_format($amount,$decimalDigits,'.','');
        }
Change this to:

Code: Select all

        $money=money_format('%!-i','9999.99');
        $decimalChr=$money[5];
        $thousandChr=$money[1];
        if($siteOption['thousandsSeparator']){
            $amount = number_format($amount,$decimalDigits,$decimalChr,$thousandChr);
        }else{
            $amount = number_format($amount,$decimalDigits,$decimalChr,'');
        }

The problem is that the localization is lost because the value is being returned in a temporary string rather than just using sprintf (I think)

bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Re: Thousand separator

Post by bamse » Sat Nov 10, 2012 9:34 pm

Thank you. That fixes it.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest