php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39126 String->float->String conversion behavior
Submitted: 2006-10-11 15:32 UTC Modified: 2006-10-11 16:13 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bobson at rpg dot pl Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5CVS-2006-10-11 (snap) 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bobson at rpg dot pl
New email:
PHP Version: OS:

 

 [2006-10-11 15:32 UTC] bobson at rpg dot pl
Description:
------------
When converting to float from string, its always use "." as a decimal separator, but echo shows decimal separator using locale definition.
Because of that there's a problem eg. in dbase function on numeric(float) fields.

Reproduce code:
---------------
setlocale(LC_ALL,"pl_PL");
echo '1.2*1=';
echo "1.2"*1;
//produce 1.2*1=1,2
echo '1,2*1=';
echo "1,2"*1;
//produce 1,2*1=1 <- this was expected to produce 1,2 float on pl_PL (in PL decimal separator is ",")

setlocale(LC_ALL,"en_EN");
echo '1.2*1=';
echo "1.2"*1;
//produce 1.2*1=1.2
echo '1,2*1=';
echo "1,2"*1;
//produce 1,2*1=1 <- correct on en_EN

//the most ugly examlpe
setlocale(LC_ALL,"pl_PL");
echo (("1.2"*1)."")*1; //produce 1 
echo (("1,2"*1)."")*1; //also produce 1 


Expected result:
----------------
on pl_PL
1
1,2

on en_EN
1.2
1

last one example code:
1
1,2

Actual result:
--------------
on pl_PL
1,2
1

on en_EN
1.2
1

last one example code:
1
1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-11 15:59 UTC] tony2001@php.net
The output may differe depending on your localem but the input must always be the same, otherwise your script would not work on servers with different locales.
 [2006-10-11 16:13 UTC] bobson at rpg dot pl
Yes and no in fact.
Using the same decimal separator on all platform is nice but-
When you using input from browser (POST) in Poland you will get "," as decimal separator when someone type from numeric keypad. 
Second:
Try to read dbase file with numeric(4,2) field and float value in it. Set locale to "pl_PL" first. Because of float->string translation using locale you will never get float from that numeric (because dbase reading procedure make float->string->float convert. float->string using locale. string->float without using locale. It makes value truncated to integer part of it).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 17:01:33 2025 UTC