|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-02-02 15:39 UTC] cmbecker69 at gmx dot de
[2015-03-19 21:24 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cmb
[2015-03-19 21:24 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 20:00:01 2025 UTC |
Description: ------------ $n - floor($n) always returns the expected result, but when comparing it to the same (float) value it evaluates to FALSE. This is regardless of whether the value comparing it to is of the same type or not. A workaround to this problem is converting the number to a string first, and then back to float. Test script: --------------- function expr_dump( $val, $equals ) { print $val." == ".$equals." "; var_dump( $val == $equals ); } function test( $v, $w ) { $n = $v - floor($v); expr_dump( $n, $w ); $n = strval( $n ); $n = floatval( $n ); expr_dump( $n, $w ); } test(2.95, .95); Expected result: ---------------- test(0.95, .95): true, true test(1.95, .95): true, true test(2.95, .95): true, true test(30.95, .95): true, true Actual result: -------------- test(0.95, .95): true, true test(1.95, .95): true, true test(2.95, .95): false, true // BAD! test(30.95, .95): false, true // BAD!