Req #45365 [Opn->Fbk]: non-native conversions from float to string

From: Date: Sat, 27 Dec 2014 20:09:12 +0000
Subject: Req #45365 [Opn->Fbk]: non-native conversions from float to string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189232@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=45365&edit=1 ID: 45365 Updated by: kalle@php.net Reported by: rasmus at mindplay dot dk Summary: non-native conversions from float to string -Status: Open +Status: Feedback Type: Feature/Change Request Package: Scripting Engine problem Operating System: * PHP Version: 5.2.6 Block user comment: N Private report: N New Comment: Please try using this snapshot: http://snaps.php.net/php-trunk-latest.tar.gz For Windows: http://windows.php.net/snapshots/ Float handling had a major revamp in 5.3, can you please try a snapshot and check if this bug still is present? Previous Comments: ------------------------------------------------------------------------ [2008-06-26 12:27:51] rasmus at mindplay dot dk 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 this bug report at https://bugs.php.net/bug.php?id=45365&edit=1

« previous php.bugs (#189232) next »