#17079 [Ctl]: setlocale changes the internal representation of floats

From: Date: Thu, 29 Aug 2002 01:14:37 +0000
Subject: #17079 [Ctl]: setlocale changes the internal representation of floats
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18102@lists.php.net to get a copy of this message
 ID:               17079
 Updated by:       sniper@php.net
 Reported By:      jonathan@tricolon.com
 Status:           Critical
-Bug Type:         Feature/Change Request
+Bug Type:         *Languages/Translation
 Operating System: Red Hat Linux 7.1
 PHP Version:      4.1.2
-Assigned To:      
+Assigned To:      hholzgra
 New Comment:

one more locale bug..



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

[2002-05-23 10:44:35] jonathan@tricolon.com

I didn't hear anything anymore, so I am just curious if this was picked
up... Thanks, Jonathan

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

[2002-05-08 04:14:04] jonathan@tricolon.com

Hi somehow it has to do with converting 'numberic'-strings to floats as
the script below shows:

<?

$rate1 = 1.123;
$amount1 = 5;
$rate2 = "1.123";
$amount2 = "5";

// set locale to English to handle the floatingpoints correctly
// first calculation with floats
setlocale (LC_ALL, 'en_US');
echo "This should be correct:<br><br>";
echo $rate1." * ".$amount1." = ".($rate1*$amount1);

// second calculation with floats converted from strings
echo "<br><br>This should be correct as well:<br><br>";
echo $rate2." * ".$amount2." = ".($rate2*$amount2);


// set locale to Dutch to show misbehaviour
// first calculation with floats
setlocale (LC_ALL, 'nl_NL');
echo "<br><br>This should still be correct:<br><br>";
echo $rate1." * ".$amount1." = ".($rate1*$amount1);

// second calculation with floats converted from strings
echo "<br><br>This should be wrong:<br><br>";
echo $rate2." * ".$amount2." = ".($rate2*$amount2);

?>

Hope this shows the 'bug' correctly!

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

[2002-05-07 14:36:57] mfischer@php.net

This is dangerous indeed. We've had already reports about this (forgot
#, or did it even only came up on php-dev@?).

Though It may sound trivial, please provide a short self-contained
script showing the (mis-)behaviour.

Marking as critical for now.

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

[2002-05-07 14:02:11] jonathan@tricolon.com

If I set my locale to Dutch in my php-script that converts currencies
for a Dutch site, I noticed that also the internal representation of
floats change as well. In Europe an amount of tenthousand dollars is
written as follows: $10.000,00 unlike the USA $10,000.00
So if I set the locale to "nl_NL" the internal representation of a
float with a point to seperate the integer part from the decimals (for
example: $amount = 68.123) is changed to a representation of a comma
','. I would like to see it changed because it messes up calculations
and the different locale settings should (IMHO) apply only to output
function and such.

Thanks,
Jonathan


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


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



Thread (18 messages)

« previous php.bugs (#18102) next »