php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45165 function money_format() : space missing from currency symbols
Submitted: 2008-06-04 07:29 UTC Modified: 2008-06-15 20:59 UTC
From: richard dot gunn at deckard dot worldonline dot co dot uk Assigned: hholzgra (profile)
Status: Not a bug Package: Math related
PHP Version: 5.2.6 OS: Linux (Ubuntu 8.04)
Private report: No CVE-ID: None
 [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 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-15 20:59 UTC] hholzgra@php.net
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;
}

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC