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
 [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-2022 The PHP Group
All rights reserved.
Last updated: Sat Aug 13 19:05:45 2022 UTC