From ce18e8d163e968f4a3066f45893d4ef54198edba Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 7 Aug 2017 11:44:32 +0100 Subject: [PATCH] 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 --- CRM/Utils/Rule.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; } /** -- 2.25.1