php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40174 is_numeric with currency values
Submitted: 2007-01-19 17:07 UTC Modified: 2007-01-20 10:44 UTC
From: sehh at altered dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.0 OS: Fedora Core Linux
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sehh at altered dot com
New email:
PHP Version: OS:

 

 [2007-01-19 17:07 UTC] sehh at altered dot com
Description:
------------
The function is_numeric() fails when the input is a value with thousand and decimal separators.

For example: 4.000,56 or 4,000.56.

We had a short discussion about this in #php irc channel and found out the following:

"4,000.56" = is USA notation
"4.000,56" = is European notation

They are perfectly valid numeric values, used in currency/weight/cubic centimeters/etc.


Suggested solutions:

1) Both notations should be accepted.

2) Only one notation should be accepted and PHP will decide which one, based on the Locale of the server/setup.

Any other suggestion is welcome.


Reproduce code:
---------------
Reproduction code:

<?php

$dolars = "4,000.56";
$euros = "4.000,56";

$rc = is_numeric($dolars);
var_dump($rc);

$rc = is_numeric($euros);
var_dump($rc);

?>

Expected result:
----------------
is_numeric should have returned TRUE in both cases.


Actual result:
--------------
is_numeric returns false for both.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-19 17:14 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2007-01-20 10:44 UTC] sehh at altered dot com
I'm sorry, i dont understand why this isn't a bug, since both numbers are perfectly valid but still rejected by is_numeric.

I went through the documentation but i can't find anything related to this issue. The docs say that is_numeric should allow an optional decimal part.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 08:01:29 2025 UTC