#49817 [Bgs]: round() couldn't handle german floats with comma
| From: | pajoye@php.net | Date: | Fri, 09 Oct 2009 09:00:29 +0000 |
| Subject: | #49817 [Bgs]: round() couldn't handle german floats with comma | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-143408@lists.php.net to get a copy of this message | ||
ID: 49817
Updated by: pajoye@php.net
Reported By: wojtech at sam-germany dot de
Status: Bogus
Bug Type: Math related
Operating System: Windows XP SP2
PHP Version: 5.2SVN-2009-10-09 (snap)
New Comment:
It expects a float, not a localized string representation of a number.
Previous Comments:
------------------------------------------------------------------------
[2009-10-09 08:58:20] wojtech at sam-germany dot de
If you think, that I hadn't seen the note, you are wrong.
I can read:
"Note: PHP doesn't handle strings like "12,300.2" correctly by
default. See converting from strings."
(I still had said "the problem is known".)
But could you explain me the reason of the behaviour?
Why don't change it to what everyone would expect?
Or I think so wrongly?
------------------------------------------------------------------------
[2009-10-09 08:43:53] pajoye@php.net
http://de3.php.net/round
------------------------------------------------------------------------
[2009-10-09 08:41:17] wojtech at sam-germany dot de
Description:
------------
The problem is known, but the result can't be the last answer.
I must calculate the body mass index for my company.
Yesterday I registered rounding errors between 0.1 and 0.3.
The problem: german doctors declares weight as "63,3" and not as
"63.3".
It was my fault trusting in PHPs typecasting.
BUT: why trying typecasting a stupid string, so round() gives a
"correct" answer?
I except returning FALSE, if the given parameter contains something
else than "0-9" and ".".
Reproduce code:
---------------
$var = "German doctors don't know the point.";
print round($var, 1);
$var = "3 german doctors dont't know the point.";
print round($var, 1);
$var = "3,467";
print round($var, 1);
$var = "3.465";
print round($var, 1);
Expected result:
----------------
FALSE
FALSE
FALSE
3,5
Actual result:
--------------
0
3
3
3.5
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49817&edit=1