Ask a Question related to PHP Development, Design and Development.
-
sniper@php.net #1
#24591 [Opn->Ver]: Using locale with , as decimal sep., floats truncated on conversion from string
ID: 24591
Updated by: [email]sniper@php.net[/email]
Reported By: arnarb at oddi dot is
-Status: Open
+Status: Verified
Bug Type: Scripting Engine problem
Operating System: Linux 2.4.18
-PHP Version: 4.3.3RC1
+PHP Version: 5.0.0b2-dev, 4.3.3RC2-dev
New Comment:
<?php
printf("%.3f\n", 3.233);
var_dump(sprintf("%.3f", 3.233) + 1);
setlocale(LC_ALL, "is_IS");
printf("%.3f\n", 3.233);
var_dump(sprintf("%.3f", 3.233) + 1);
?>
Output:
3.233
float(4.233)
3,233
int(4)
Previous Comments:
------------------------------------------------------------------------
[2003-07-10 10:58:33] arnarb at oddi dot is
Tried upgrading to 4.3.3RC1, still the same. Therefore bumping the
version tag on this report.
------------------------------------------------------------------------
[2003-07-10 10:52:19] arnarb at oddi dot is
Description:
------------
When strings containing numbers in the locale format, and the locale
uses , as the decimal seperator, converting the string to a float cuts
off at the , and returns the integer part.
This was addressed in bugs #17105, #17815 and others. Those reports
were closed and the problem was claimed to be fixed in CVS as of
November 2002 by iliaa and sniper.
This bug is however still present in 4.3.2, as the reproduce code
demonstrates.
A quick look indicated that libc's strtod was being used for the
conversion, I verified that it is working on my platform.
Reproduce code:
---------------
<?php
printf("%.3f\n", 3.233);
print sprintf("%.3f", 3.233)+1;
print "\n";
setlocale(LC_ALL, "is_IS");
printf("%.3f\n", 3.233);
print sprintf("%.3f", 3.233)+1;
print "\n";
?>
Expected result:
----------------
3.233
4.233
3,233
4,233
Actual result:
--------------
3.233
4.233
3,233
4
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=24591&edit=1[/url]
sniper@php.net Guest
-
#40576 [NEW]: long values are truncated to 6 decimal digits upon encoding
From: giunta dot gaetano at sea-aeroportimilano dot it Operating system: win2k sp4 PHP version: 5.2.1 PHP Bug Type: ... -
#40360 [NEW]: current locale affects how json_encode encodes floats
From: ftl_ at freemail dot hu Operating system: Gentoo Linux PHP version: 5.2.0 PHP Bug Type: Variables related Bug... -
#40235 [NEW]: serialize breaks with floats if locale is set to de_DE
From: tacker@php.net Operating system: Gentoo Linux PHP version: 5.2.1RC3 PHP Bug Type: Variables related Bug description: ... -
#24591 [Bgs]: Using locale with , as decimal sep., floats truncated on conversion from string
ID: 24591 User updated by: arnarb at oddi dot is Reported By: arnarb at oddi dot is Status: Bogus Bug Type: ... -
#24591 [Opn]: Using locale with , as decimal sep., floats truncated on conversion from string
ID: 24591 User updated by: arnarb at oddi dot is Reported By: arnarb at oddi dot is Status: Open Bug Type: ...



Reply With Quote

