php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44041 number_format returns garbage for thousands sep and latvian locale
Submitted: 2008-02-04 15:18 UTC Modified: 2008-02-08 23:14 UTC
From: trickie at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.2.5 OS: Gentoo Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
37 - 31 = ?
Subscribe to this entry?

 
 [2008-02-04 15:18 UTC] trickie at gmail dot com
Description:
------------
If you set the locale to 'lv_LV.UTF-8' and have the locale generated on your system, then the code below will return garbage as the 'thousands separator'. It displays ok for me when running with CLI SAPI

Reproduce code:
---------------
<?php
if (false !== setlocale(LC_ALL, 'lv_LV.UTF-8')) {
    $locale_info = localeconv();
    echo number_format(20000,0,$locale_info['decimal_point'], $locale_info['thousands_sep']);
}
?>


Expected result:
----------------
20 000

Actual result:
--------------
20&#65533;000

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-05 05:09 UTC] jani@php.net
What does this output:

<?php
if (false !== setlocale(LC_ALL, 'lv_LV.UTF-8')) {
  $locale_info = localeconv();
  var_dump($locale_info);
}
?>
 [2008-02-05 07:31 UTC] trickie at gmail dot com
Output requested:

array(18) {
  ["decimal_point"]=>
  string(1) ","
  ["thousands_sep"]=>
  string(2) "&#65533;&#65533;"
  ["int_curr_symbol"]=>
  string(4) "LVL "
  ["currency_symbol"]=>
  string(2) "Ls"
  ["mon_decimal_point"]=>
  string(1) ","
  ["mon_thousands_sep"]=>
  string(2) "&#65533;&#65533;"
  ["positive_sign"]=>
  string(0) ""
  ["negative_sign"]=>
  string(1) "-"
  ["int_frac_digits"]=>
  int(2)
  ["frac_digits"]=>
  int(2)
  ["p_cs_precedes"]=>
  int(1)
  ["p_sep_by_space"]=>
  int(1)
  ["n_cs_precedes"]=>
  int(1)
  ["n_sep_by_space"]=>
  int(1)
  ["p_sign_posn"]=>
  int(3)
  ["n_sign_posn"]=>
  int(3)
  ["grouping"]=>
  array(2) {
    [0]=>
    int(3)
    [1]=>
    int(3)
  }
  ["mon_grouping"]=>
  array(2) {
    [0]=>
    int(3)
    [1]=>
    int(3)
  }
}
 [2008-02-07 00:42 UTC] jani@php.net
The "garbage" you get is a non-breaking space in UTF-8. You can always use utf_decode() on it:

<?php
if (false !== setlocale(LC_ALL, 'lv_LV.UTF-8')) {
    $locale_info = localeconv();
    echo number_format(20000,0,$locale_info['decimal_point'],
utf8_decode($locale_info['thousands_sep']));
}
?>

Since unicode support is coming in PHP6 and will not be addressed before, this is "wont fix" in earlier versions.

I suggest you really don't use setlocale() if you want to use UTF-8.
At least not for numbers.

 [2008-02-07 07:40 UTC] trickie at gmail dot com
Thanks for the tip.
 [2008-02-08 23:14 UTC] stas@php.net
You may also want to look at http://pecl.php.net/package/intl
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 13:01:29 2024 UTC