php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31963 zend_strtod.c does not respect locale.
Submitted: 2005-02-14 09:42 UTC Modified: 2005-02-14 10:11 UTC
From: wulff at fyens dot dk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.10 OS: 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 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: wulff at fyens dot dk
New email:
PHP Version: OS:

 

 [2005-02-14 09:42 UTC] wulff at fyens dot dk
Description:
------------
The Zend engine does not respect the current locale when it converts from a string to a float.

Zend assumes that all numbers have a "." as a decimal seperator. This is not the case in many parts of the world.

Included in this bug is a bit of "non-portable" code that solves the problem. This may not be the most elegant solution but it illustrates what needs to be fixed. 

Here are my changes to Zend/zend_strtod.c at line 1249:

//      CONST char decimal_point = ',';

        char decimal_point = '.';
        #ifdef HAVE_LOCALE_H
        struct lconv* current_locale;
        current_locale=localeconv();
        decimal_point=(*(*current_locale).decimal_point);
        #endif


Reproduce code:
---------------
<?php
  setLocale(LC_ALL,"de_DE");
  echo ("2,2"*2)."\n";
?>


Expected result:
----------------
The result one would expect if PHP respected locale:
4,4



Actual result:
--------------
What you get is:
4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-14 10:11 UTC] derick@php.net
THe reason why we introduced this zend_strtod.c was exactly because of this reason. This is not a bug, but expected and wanted behavior.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 18:01:30 2024 UTC