php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #57369 Take into account the locale for Float
Submitted: 2006-11-11 14:58 UTC Modified: 2006-11-11 16:31 UTC
From: ramsey@php.net Assigned:
Status: Not a bug Package: filter (PECL)
PHP Version: 5.2.0 OS: Mac OS X 10.4.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ramsey@php.net
New email:
PHP Version: OS:

 

 [2006-11-11 14:58 UTC] ramsey@php.net
Description:
------------
Even when setting the locale to one that uses commas for the decimal point separator in a floating point number, the FILTER_VALIDATE_FLOAT and FILTER_SANITIZE_NUMBER_FLOAT constants do not recognize the comma as a proper separator. For internationalization, these filters should allow the comma (or take the locale into account and allow the comma).

Reproduce code:
---------------
<?php

setlocale(LC_ALL, 'de_DE');

$float1 = '42.3';
$float2 = '42,3';

var_dump(filter_var($float1, FILTER_VALIDATE_FLOAT));
var_dump(filter_var($float2, FILTER_VALIDATE_FLOAT));

var_dump(filter_var($float1, FILTER_SANITIZE_NUMBER_FLOAT, array('flags' => FILTER_FLAG_ALLOW_FRACTION)));
var_dump(filter_var($float2, FILTER_SANITIZE_NUMBER_FLOAT, array('flags' => FILTER_FLAG_ALLOW_FRACTION)));

?>

Expected result:
----------------
float(42.3)
float(42.3)
string(4) "42.3"
string(4) "42.3"

Actual result:
--------------
float(42.3)
bool(false)
string(4) "42.3"
string(3) "423"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-11 16:31 UTC] pierre dot php at gmail dot com
Please use the "decimal" option. It does not use the locale, it works with user inputs which can be in any kind of locale.
 [2017-01-20 14:48 UTC] neil at crook dot es
The decimal option does not work for FILTER_SANITIZE_NUMBER_FLOAT. It still strips the comma.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 19:01:29 2024 UTC