php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40653 strval() and floatval() behave differently
Submitted: 2007-02-27 01:39 UTC Modified: 2007-02-27 12:27 UTC
From: plyrvt at mail dot ru Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.1 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: plyrvt at mail dot ru
New email:
PHP Version: OS:

 

 [2007-02-27 01:39 UTC] plyrvt at mail dot ru
Description:
------------
Either strval() or floatval() is buggy. They can respect locale or ignore locale, but at least both do things the same way!

Reproduce code:
---------------
<?php
 setlocale(LC_NUMERIC, "ANY_LOCALE_WITH_,_SEPARATOR");
 $f=1.2;
 $s=strval($f);
 $f=floatval($s);
 var_dump($f);

// expected: 1.2 or 1,2
// actual: 1
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-27 12:27 UTC] tony2001@php.net
The point is that string representation of doubles (i.e. double-to-string) always depends on locale settings.
But string-to-double always ignores locale and uses "." as decimal separator.
That might sound inconsistent, but consider this first: 
1) we DO want users to be able to output numbers in locale-dependent format;
2) we DON'T want scripts to depend on locale or we may end up with scripts working/not working with particular locales.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 08:02:42 2024 UTC