Bug #76435 [Opn->Csd]: Float with decimals Filter issue with Ca_fr locale
| From: | cmb@php.net | Date: | Thu, 05 Aug 2021 16:50:18 +0000 |
| Subject: | Bug #76435 [Opn->Csd]: Float with decimals Filter issue with Ca_fr locale | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235618@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76435&edit=1
ID: 76435
Updated by: cmb@php.net
Reported by: joel dot lamothe dot 42 at gmail dot com
Summary: Float with decimals Filter issue with Ca_fr locale
-Status: Open
+Status: Closed
Type: Bug
Package: Filter related
Operating System: Windows
PHP Version: 7.1.18
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This issue is fixed as of PHP 8.0.0[1], where float to string
conversion (which is actually the culprit here) is no longer
locale aware. This fix won't be backported.
[1] <https://3v4l.org/f08P7>
Previous Comments:
------------------------------------------------------------------------
[2018-06-09 12:55:20] cmb@php.net
Not only is FILTER_SANITIZE_NUMBER_FLOAT not locale aware, but
there also is no possibility to manually override the decimal and
thousand separators[1] (like for FILTER_VALIDATE_FLOAT), which
rather limits its usefulness.
In this case one can get around this limitation by using the flag
FILTER_FLAG_ALLOW_THOUSAND instead of
FILTER_FLAG_ALLOW_FRACTION[2], but that's quite a hack.
[1] <https://github.com/php/php-src/blob/PHP-7.2.7/ext/filter/sanitizing_filters.c#L358-L367>
[2] <https://3v4l.org/IILhX>
------------------------------------------------------------------------
[2018-06-09 00:29:30] joel dot lamothe dot 42 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/filter.filters.sanitize
---
When setting the locale to fr_CA, using filter_var with decimal numbers is behaving irregularly
since the comma is the decimal separator in fr_CA, the sanitized float becomes an int losing its
comma.
filter_var is either not coded in a locale dependent way or this below scenario is not being caught
in its handling of the locale.
Test script:
---------------
<?php
setlocale(LC_ALL, 'fr_CA.utf-8');
$number = 25 / 2;
$temp = filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
echo $temp;
?>
Expected result:
----------------
12,5
Actual result:
--------------
125
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76435&edit=1