Add CRM.sigfig utility
[civicrm-core.git] / CRM / Utils / Rule.php
index c9b791157adb69af4c1f1f04664a93b506ced839..f5b1df363f9f7e0c4ee4056614b1782e0bf37a85 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -429,7 +429,8 @@ class CRM_Utils_Rule {
       'currency', array(
         'keyColumn' => 'name',
         'labelColumn' => 'symbol',
-      ));
+      )
+    );
     $value = str_replace($currencySymbols, '', $value);
 
     if ($config->monetaryThousandSeparator) {
@@ -442,7 +443,9 @@ class CRM_Utils_Rule {
     // ugly fix for CRM-6391: do not drop the thousand separator if
     // it looks like it’s separating decimal part (because a given
     // value undergoes a second cleanMoney() call, for example)
-    if ($mon_thousands_sep != '.' or substr($value, -3, 1) != '.') {
+    // CRM-15835 - in case the amount/value contains 0 after decimal
+    // eg 150.5 the following if condition will pass
+    if ($mon_thousands_sep != '.' or (substr($value, -3, 1) != '.' && substr($value, -2, 1) != '.')) {
       $value = str_replace($mon_thousands_sep, '', $value);
     }
 
@@ -611,7 +614,7 @@ class CRM_Utils_Rule {
   }
 
   /**
-   * Check if there is a record with the same name in the db
+   * Check if there is a record with the same name in the db.
    *
    * @param string $value
    *   The value of the field we are checking.
@@ -798,4 +801,5 @@ class CRM_Utils_Rule {
   public static function qfKey($key) {
     return ($key) ? CRM_Core_Key::valid($key) : FALSE;
   }
+
 }