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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 13:01:28 2025 UTC