2015-07-15

How to compare float numbers in php

/**
 * Return true if $a equals to $b
 *
 * @param float $a
 * @param float $b
 *
 * @return bool
 */
function isEqualFloat($a, $b)
{
    $epsilon = 0.00001;

    if (abs($a - $b) < $epsilon) {
        return true;
    }

    return false;
}