X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FMoney.php;h=bbe8072a25aec4b4fa4956af0f994538e107f433;hb=fdb2f1d2f412d08b27e59c793ab9b85b810f4a2c;hp=0e8cd6d76cc9497462ee6eaf066d9ae67f8176a7;hpb=53e5c140fb12deef04b6350bda8c44cd8771cad4;p=civicrm-core.git diff --git a/CRM/Utils/Money.php b/CRM/Utils/Money.php index 0e8cd6d76c..bbe8072a25 100644 --- a/CRM/Utils/Money.php +++ b/CRM/Utils/Money.php @@ -138,18 +138,13 @@ class CRM_Utils_Money { /** * Tests if two currency values are equal, taking into account the currency's - * precision, so that if the difference between the two values is less than - * one more order of magnitude for the precision, then the values are - * considered as equal. So, if the currency has precision of 2 decimal - * points, a difference of more than 0.001 will cause the values to be - * considered as different. Anything less than 0.001 will be considered as - * equal. + * precision, so that the two values are compared as integers after rounding. * * Eg. * - * 1.2312 == 1.2319 with a currency precision of 2 decimal points - * 1.2310 != 1.2320 with a currency precision of 2 decimal points - * 1.3000 != 1.2000 with a currency precision of 2 decimal points + * 1.231 == 1.232 with a currency precision of 2 decimal points + * 1.234 != 1.236 with a currency precision of 2 decimal points + * 1.300 != 1.200 with a currency precision of 2 decimal points * * @param $value1 * @param $value2 @@ -158,14 +153,9 @@ class CRM_Utils_Money { * @return bool */ public static function equals($value1, $value2, $currency) { - $precision = 1 / pow(10, self::getCurrencyPrecision($currency) + 1); - $difference = self::subtractCurrencies($value1, $value2, $currency); + $precision = pow(10, self::getCurrencyPrecision($currency)); - if (abs($difference) > $precision) { - return FALSE; - } - - return TRUE; + return (int) round($value1 * $precision) == (int) round($value2 * $precision); } /**