From:             rasmus at mindplay dot dk
Operating system: Any
PHP version:      5.2.6
PHP Bug Type:     Scripting Engine problem
Bug description:  non-native conversions from float to string

Description:
------------
When using strval(), implicit conversion or type-casting, floats are
converted using locale-aware display formatting, rather than native
formatting, as understood by most other software (and PHP itself).

Please understand that this is a complex problem, which requires a lengthy
analysis and many examples. I have spent almost 6 hours analyzing this
problem in-depth, and created a complete report explaining the problem,
suggesting changes, and recommending ways to implement these changes.

Please, don't discard this report without careful consideration - there
are fundamental problems with float-handling in PHP, which should be taken
seriously.

For the full description and examples, please see this page:

http://public.test.fynskemedier.dk/float/

Thank You.


Reproduce code:
---------------
<?php

setlocale(LC_NUMERIC, 'danish');

function ftos($f) {
    return is_float($f) ? sprintf('%.14F', $f) : 'NaN';
}

$a = 1234.01234567890123456789;

echo "accurate value: " . ftos($a) . "\n\n";
echo "casting float to string: ";
$s = (string) $a;
var_dump($s);
echo "casting back to float: ";
echo ftos( (float) $s ) . "\n\n";

?>

The above is a very simple example, demonstrating one of the issues most
commonly encountered by beginning PHP developers.

Please find many more examples and in-depth explanations below:

http://public.test.fynskemedier.dk/float/


Expected result:
----------------
accurate value: 1234.01234567890128

casting float to string: string(19) "1234.01234567890128"
casting back to float: 1234.01234567890128


Actual result:
--------------
accurate value: 1234.01234567890128

casting float to string: string(13) "1234,01234568"
casting back to float: 1234.00000000000000


-- 
Edit bug report at http://bugs.php.net/?id=45365&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=45365&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=45365&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=45365&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45365&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=45365&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45365&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45365&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45365&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45365&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45365&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=45365&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=45365&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45365&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45365&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45365&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45365&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45365&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45365&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45365&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45365&r=mysqlcfg

Reply via email to