Req #45365 [Fbk->NoF]: non-native conversions from float to string
| From: | php-bugs at lists dot php dot net | Date: | Sun, 04 Jan 2015 04:22:14 +0000 |
| Subject: | Req #45365 [Fbk->NoF]: non-native conversions from float to string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189635@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: php-bugs@lists.php.net
Reported by: rasmus at mindplay dot dk
Summary: non-native conversions from float to string
-Status: Feedback
+Status: No Feedback
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.2.6
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2014-12-27 20:09:12] kalle@php.net
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?
------------------------------------------------------------------------
[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