Bug #78113 [Ver->Csd]: Number formatting does not properly handle locales with multibyte decimal_point

From: Date: Mon, 19 Oct 2020 12:51:32 +0000
Subject: Bug #78113 [Ver->Csd]: Number formatting does not properly handle locales with multibyte decimal_point
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229746@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78113&edit=1 ID: 78113 Updated by: cmb@php.net Reported by: bjorsch at wikimedia dot org Summary: Number formatting does not properly handle locales with multibyte decimal_point -Status: Verified +Status: Closed Type: Bug Package: *General Issues Operating System: Debian sid PHP Version: 7.3Git-2019-06-05 (Git) -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Well, as of PHP 8.0.0, float to string conversion is no longer depending on the current locale[1]. I don't think it makes sense to fix this long standing issue for the stable versions, so I'm closing this ticket. [1] <https://wiki.php.net/rfc/locale_independent_float_to_string> Previous Comments: ------------------------------------------------------------------------ [2019-06-05 17:38:27] bjorsch at wikimedia dot org Description: ------------ PHP's support for locales in its number formatting assumes that 'decimal_point' will be a single char. This is not always the case, however. On my system, for example, locale "ps_AF" has it as "٫" as represented in UTF-8 encoding.[1] PHP uses only the first byte of that, producing "Ù" in the console output. This seems to affect at least string casts and the printf() family of functions. I note though that number_format() is not affected, it works fine when multibyte values are passed for the separators. I reproduce this in PHP 7.0.31, 7.1.20, 7.2.11, 7.3.4, and current git master (5f3ee3afe7). [1]: Note this is not really a Unicode issue though. If the locale had decimal_point set to the string "dec" for some reason, PHP would similarly use only "d". Test script: --------------- <?php echo PHP_VERSION . "\n"; $n = 123456.789; // If this locale doesn't exist on your system or doesn't have a non-ASCII // 'decimal_point', change it to one that does. var_dump( setlocale( LC_NUMERIC, 'ps_AF' ) ); var_dump( localeconv() ); echo "$n\n"; printf( "%.15g\n", $n ); echo number_format( $n, 3, localeconv()['decimal_point'], localeconv()['thousands_sep'] ) . "\n"; Expected result: ---------------- 8.0.0-dev string(5) "ps_AF" array(18) { ["decimal_point"]=> string(2) "٫" ["thousands_sep"]=> string(2) "٬" ["int_curr_symbol"]=> string(0) "" ["currency_symbol"]=> string(0) "" ["mon_decimal_point"]=> string(0) "" ["mon_thousands_sep"]=> string(0) "" ["positive_sign"]=> string(0) "" ["negative_sign"]=> string(0) "" ["int_frac_digits"]=> int(127) ["frac_digits"]=> int(127) ["p_cs_precedes"]=> int(127) ["p_sep_by_space"]=> int(127) ["n_cs_precedes"]=> int(127) ["n_sep_by_space"]=> int(127) ["p_sign_posn"]=> int(127) ["n_sign_posn"]=> int(127) ["grouping"]=> array(1) { [0]=> int(3) } ["mon_grouping"]=> array(0) { } } 123456٫789 123456٫789 123٬456٫789 Actual result: -------------- 8.0.0-dev string(5) "ps_AF" array(18) { ["decimal_point"]=> string(2) "٫" ["thousands_sep"]=> string(2) "٬" ["int_curr_symbol"]=> string(0) "" ["currency_symbol"]=> string(0) "" ["mon_decimal_point"]=> string(0) "" ["mon_thousands_sep"]=> string(0) "" ["positive_sign"]=> string(0) "" ["negative_sign"]=> string(0) "" ["int_frac_digits"]=> int(127) ["frac_digits"]=> int(127) ["p_cs_precedes"]=> int(127) ["p_sep_by_space"]=> int(127) ["n_cs_precedes"]=> int(127) ["n_sep_by_space"]=> int(127) ["p_sign_posn"]=> int(127) ["n_sign_posn"]=> int(127) ["grouping"]=> array(1) { [0]=> int(3) } ["mon_grouping"]=> array(0) { } } 123456Ù789 123456Ù789 123٬456٫789 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78113&edit=1

« previous php.bugs (#229746) next »