ID:               35215
 Updated by:       [EMAIL PROTECTED]
 Reported By:      timo dot hummel at 4fb dot de
-Status:           Open
+Status:           Bogus
 Bug Type:         Strings related
 Operating System: any
 PHP Version:      5.0.5
 New Comment:

Not a bug.

I don't like that behaviour either, anyway there's number_format() and
*printf().



Previous Comments:
------------------------------------------------------------------------

[2005-11-14 15:51:28] timo dot hummel at 4fb dot de

Description:
------------
Currently, the whole way PHP does type juggling is affected using
setlocale. 

Right now, PHP respects the setlocale-Settings for LC_NUMERIC when
doing type-juggling (e.g. converting a float to a string or when
outputting data):

$float = 0.12;
setlocale(LC_ALL, "de_DE");
echo $float;

The simple example above outputs 0,12. If you need to build up SQL
queries, this behaviour is unwanted and causes errors:

$float = 0.12;
setlocale(LC_ALL, "de_DE");
$sql = "SELECT * FROM test WHERE value=$float;";

The query will be "juggled" to SELECT * FROM test WHERE value=0,12; -
which is not the expected result. 

If setlocale is used, there's no way (at least not to my knowledge) to
access the original, english (I also call it technical) representation
of a floating point number. 

This is not really a bug, but rather a limitation by design, but it
effectively prevents PHP developers from implementing multi-lingual
applications.



Reproduce code:
---------------
<?php
/* Nicer output for browsers */
echo "<pre>";

/* Predefine some variables to play around with */
$float = 0.12;
$sql = "SELECT * FROM test WHERE amount=";

setlocale(LC_ALL, "C");         // Set standard locale
echo strval($float). "\n";      // Outputs 0.12, which is OK
echo $sql . $float."\n";    // Outputs SELECT * FROM test WHERE
amount=0.12, which can be used by a database.


setlocale(LC_ALL, "de_DE");     // Set german locale
echo strval($float). "\n";      // Outputs 0,12, which is OK for display
purposes, but not for data processing
echo $sql . $float."\n";    // Outputs SELECT * FROM test WHERE
amount=0,12, which cannot be used by a database with english locale.

echo "</pre>";
?>



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35215&edit=1

Reply via email to