Bug #55160 [Opn->Nab]: Unexpected result on bccomp when using any decimal comma locale
| From: | mike@php.net | Date: | Wed, 02 Oct 2013 10:58:26 +0000 |
| Subject: | Bug #55160 [Opn->Nab]: Unexpected result on bccomp when using any decimal comma locale | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181950@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55160&edit=1
ID: 55160
Updated by: mike@php.net
Reported by: everton at faccat dot br
Summary: Unexpected result on bccomp when using any decimal
comma locale
-Status: Open
+Status: Not a bug
Type: Bug
Package: BC math related
Operating System: Ubuntu 10.04 LTS 64bits
PHP Version: trunk-SVN-2011-07-08 (snap)
Block user comment: N
Private report: N
New Comment:
Nevertheless it is expected behaviour.
Argument type of these functions is string.
This is a bug report about an unexpected result not a feature request to implement some magic
non-locale-aware string cast.
Sorry :)
Previous Comments:
------------------------------------------------------------------------
[2013-10-02 10:07:14] nikic@php.net
@mike PHP's shitty float to string cast shouldn't impede the workings of bcmath.
We've had this problem in the past several times (with stuff like JSON etc) and the solution is
to use some custom printf modifier for this.
------------------------------------------------------------------------
[2013-10-02 09:29:09] mike@php.net
This is actually expected behaviour because bcmath operates on strings and PHP casts numbers to
strings according to locale.
------------------------------------------------------------------------
[2011-07-08 08:36:47] everton at faccat dot br
added OS additional information
------------------------------------------------------------------------
[2011-07-08 08:27:56] everton at faccat dot br
Description:
------------
Unexpected result on bccomp when using any decimal comma locale.
If an operand is a fraction, and the other is zero, the result seems to be wrong.
Test script:
---------------
<?php
print setlocale(LC_ALL, "C")."\n";
print 1.1."\n";
print bccomp(1.1, 0)."\n";
//changing locale to a country which uses decimal comma
print setlocale(LC_ALL, "en_DK.UTF-8")."\n";
print 1.1."\n";
print bccomp(1.1, 0)."\n";
print setlocale(LC_ALL, "pt_BR.UTF-8")."\n";
print 1.1."\n";
print bccomp(1.1, 0)."\n";
?>
Expected result:
----------------
C
1.1
1
en_DK.UTF-8
1,1
1
pt_BR.UTF-8
1,1
1
Actual result:
--------------
C
1.1
1
en_DK.UTF-8
1,1
0
pt_BR.UTF-8
1,1
0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55160&edit=1