From: Matthew Wire Date: Mon, 7 Aug 2017 10:44:32 +0000 (+0100) Subject: Support multiple decimal places in CRM_Utils_Rule::money for currencies such as bitco... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ce18e8d163e968f4a3066f45893d4ef54198edba;p=civicrm-core.git Support multiple decimal places in CRM_Utils_Rule::money for currencies such as bitcoin, also helps towards CRM-20772 which requires higher precision decimals to be stored in the database to calculate tax inclusive amounts correctly --- diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index a40286d4b5..897aa5dbbd 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -574,7 +574,10 @@ class CRM_Utils_Rule { return TRUE; } - return preg_match('/(^-?\d+\.\d?\d?$)|(^-?\.\d\d?$)/', $value) ? TRUE : FALSE; + // Allow values such as -0, 1.024555, -.1 + // We need to support multiple decimal places here, not just the number allowed by locale + // otherwise tax calculations break when you want the inclusive amount to be a round number (eg. £10 inc. VAT requires 8.333333333 here). + return preg_match('/(^-?\d+\.?\d*$)|(^-?\.\d+$)/', $value) ? TRUE : FALSE; } /**