php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55160 Unexpected result on bccomp when using any decimal comma locale
Submitted: 2011-07-08 08:27 UTC Modified: 2013-10-02 10:58 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: everton at faccat dot br Assigned:
Status: Not a bug Package: BC math related
PHP Version: trunk-SVN-2011-07-08 (snap) OS: Ubuntu 10.04 LTS 64bits
Private report: No CVE-ID: None
 [2011-07-08 08:27 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-08 08:36 UTC] everton at faccat dot br
-Operating System: Linux Ubuntu +Operating System: Ubuntu 10.04 LTS 64bits
 [2011-07-08 08:36 UTC] everton at faccat dot br
added OS additional information
 [2013-10-02 09:29 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-10-02 09:29 UTC] mike@php.net
This is actually expected behaviour because bcmath operates on strings and PHP casts numbers to strings according to locale.
 [2013-10-02 10:07 UTC] nikic@php.net
-Status: Not a bug +Status: Open
 [2013-10-02 10:07 UTC] 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 10:58 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-10-02 10:58 UTC] mike@php.net
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 :)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Oct 20 03:01:26 2019 UTC