Re:I still love PHP and JavaScript
by zeroonetwothree on Tuesday August 02, 2022 @10:13PM
(#32326843)
This is hardly specific to PHP. You should never compare IEEE floats using equality.
[ Parent
| on HN ]
It is absolutely the fault of PHP. You absolutely can compare IEEE floats using equality. Often it isn't what you want but this totally should work.
In this case PHP is unexpectedly rounding floats for display.
~ python3
Python 3.9.13 (main, May 24 2022, 21:28:44)
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> b = 46333.48000000001
>>> b
46333.48000000001
~ php -a
Interactive shell
php > $b = 46333.48000000001;
php > echo $b;
46333.48
Re:I still love PHP and JavaScript
by unethical_ban on Wednesday August 03, 2022 @12:55AM
(#32327806)
Isn't it the fault of the interpreter that it shows a rounded value without being promoted to?