|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-06-04 07:29 UTC] richard dot gunn at deckard dot worldonline dot co dot uk
Description:
------------
I noticed that the money_format() function appears to work in an inconsistent manner depending on the locale.
(Compare the expected output with the actual output)
I would expect GBP, CAD and AUD to be formatted the same as USD - i.e. a space between the currency symbol and the numeric.
It's a minor issue with an easy workaround, but I'd thought I'd "do the right thing" and raise a bug report.
Reproduce code:
---------------
$number = 100000.698 ;
$arrCountry = array ('GB', 'US', 'CA', 'AU') ;
foreach ($arrCountry as $currCountry) {
$locale = 'en_' . $currCountry . '.UTF-8';
setlocale (LC_MONETARY, $locale);
$locale_info = localeconv();
$currency = $locale_info['int_curr_symbol'];
$amount = money_format('%i', $number);
printf ("%s [%s] %s \n",$locale, $currency, $amount);
}
Expected result:
----------------
en_GB.UTF-8 [GBP ] GBP 100,000.70
en_US.UTF-8 [USD ] USD 100,000.70
en_CA.UTF-8 [CAD ] CAD 100,000.70
en_AU.UTF-8 [AUD ] AUD 100,000.70
Actual result:
--------------
en_GB.UTF-8 [GBP ] GBP100,000.70
en_US.UTF-8 [USD ] USD 100,000.70
en_CA.UTF-8 [CAD ] CAD100,000.70
en_AU.UTF-8 [AUD ] AUD100,000.70
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 02:00:01 2025 UTC |
This is actually a libc problem, PHP just passes through the result of the strfmon() library call. You can verify this using the following small C test program, it can be built and run using "make money_format && ./money_format" and it's result is en_GB.UTF8 [GBP ] GBP100,000.70 en_US.UTF8 [USD ] USD 100,000.70 en_CA.UTF8 [CAD ] CAD100,000.70 en_AU.UTF8 [AUD ] AUD100,000.70 too -- 8< ---- money_format.c ------- #include <stdio.h> #include <stdlib.h> #include <locale.h> #include <monetary.h> int main(int argc, char **argv) { char buf[1000], **pCountry, *arrCountry[] = {"en_GB.UTF8", "en_US.UTF8", "en_CA.UTF8", "en_AU.UTF8", NULL} ; struct lconv *locale_info; float number = 100000.698 ; for (pCountry = arrCountry; *pCountry; pCountry++) { setlocale (LC_MONETARY, *pCountry); locale_info = localeconv(); strfmon(buf, 1000, "%i", number); printf("%s [%s] %s\n", *pCountry, locale_info->int_curr_symbol, buf); } return EXIT_SUCCESS; }