method compareFloats documentation in bbn\X

Compares two float numbers with the given operator.

Example

X::compareFloats(2.0, 4.0, '<'); // (bool) true X::compareFloats(2.56222223, 2.56222223, '<=') // (bool) true X::compareFloats(2.5623, 2.5623, '<') // (bool) false function($v1, $v2, string $op = '===', int $pr = 4) { $v1 = round((float)$v1 * pow(10, $pr)); $v2 = round((float)$v2 * pow(10, $pr)); switch ($op) { case '===': return $v1 === $v2; case '==': return $v1 == $v2; case '>=': return $v1 >= $v2; case '<=': return $v1 <= $v2; case '>': return $v1 > $v2; case '<': return $v1 < $v2; } return false; }

Compares two float numbers with the given operator. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.