Bug #39158 [Com]: FILTER_VALIDATE_FLOAT doesn't uses decimal_point from locale

From: Date: Sun, 15 Dec 2019 16:03:09 +0000
Subject: Bug #39158 [Com]: FILTER_VALIDATE_FLOAT doesn't uses decimal_point from locale
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224313@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=39158&edit=1 ID: 39158 Comment by: drtechno at mail dot com Reported by: andiesPostfach at web dot de Summary: FILTER_VALIDATE_FLOAT doesn't uses decimal_point from locale Status: Not a bug Type: Bug Package: Filter related Operating System: Suse Linux 9.3 PHP Version: 5.2.0RC5 Block user comment: N Private report: N New Comment: like above (according to pajoye@php.net) correct, and the text book way: $out = filter_var($float, FILTER_VALIDATE_FLOAT, array("options"=>array('decimal' => ','))); or use this one since the character is the same.... $out=filter_var($float, FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_THOUSAND); Previous Comments: ------------------------------------------------------------------------ [2006-10-14 15:41:58] pajoye@php.net It does not use the LOCALE as it filters external data (from browsers or other clients). The default decimal separator is '.'. You have to use the "decimal" filter option to define ',' as decimal operator: $out = filter_var($float, FILTER_VALIDATE_FLOAT, array("options"=>array('decimal' => ','))); ------------------------------------------------------------------------ [2006-10-14 14:38:37] andiesPostfach at web dot de Obviously ',' isn't allowed ! ------------------------------------------------------------------------ [2006-10-14 10:55:33] tony2001@php.net Both "." and "," are allowed if you didn't specify your own. This is expected behaviour. ------------------------------------------------------------------------ [2006-10-14 10:32:11] andiesPostfach at web dot de Description: ------------ FILTER_VALIDATE_FLOAT should use the decimal point info from the given locale. In my case (in Germany) it should use ','. Reproduce code: --------------- $loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu'); echo "Preferred locale for german on this system is '$loc_de'"; $locale_info = localeconv(); print_r($locale_info); // This should work an give 0,27 $value = "0,27"; echo "Value is: ".filter_var( $value, FILTER_VALIDATE_FLOAT ); // This shouldn't work but it gives 0,27 $value = "0.27"; echo "Value is: ".filter_var( $value, FILTER_VALIDATE_FLOAT ); Expected result: ---------------- Preferred locale for german on this system is 'de_DE@euro'Array ( [decimal_point] => , [thousands_sep] => . [int_curr_symbol] => EUR [currency_symbol] => ? [mon_decimal_point] => , [mon_thousands_sep] => . [positive_sign] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_precedes] => 0 [p_sep_by_space] => 1 [n_cs_precedes] => 0 [n_sep_by_space] => 1 [p_sign_posn] => 1 [n_sign_posn] => 1 [grouping] => Array ( [0] => 3 [1] => 3 ) [mon_grouping] => Array ( [0] => 3 [1] => 3 ) ) Value for 0,27 is: 0,27<br /> Value for 0.27 is: <br /> Actual result: -------------- Preferred locale for german on this system is 'de_DE@euro'Array ( [decimal_point] => , [thousands_sep] => . [int_curr_symbol] => EUR [currency_symbol] => ? [mon_decimal_point] => , [mon_thousands_sep] => . [positive_sign] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_precedes] => 0 [p_sep_by_space] => 1 [n_cs_precedes] => 0 [n_sep_by_space] => 1 [p_sign_posn] => 1 [n_sign_posn] => 1 [grouping] => Array ( [0] => 3 [1] => 3 ) [mon_grouping] => Array ( [0] => 3 [1] => 3 ) ) Value for 0,27 is: <br /> Value for 0.27 is: 0,27<br /> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=39158&edit=1

« previous php.bugs (#224313) next »