APIv4 - Add SortableEntity type which auto-adjusts weights
[civicrm-core.git] / CRM / Utils / Number.php
index 3dae925661efe6b395d181f0055199a3f9f24253..790fdd1278e233b90f54f94591226b5e065c0a80 100644 (file)
@@ -104,4 +104,23 @@ class CRM_Utils_Number {
     }
   }
 
+  /**
+   * Format number for display according to the current or supplied locale.
+   *
+   * Note this should not be used in conjunction with any calls to
+   * replaceCurrencySeparators as this function already does that.
+   *
+   * @param string $amount
+   * @param string $locale
+   *
+   * @return string
+   * @throws \Brick\Money\Exception\UnknownCurrencyException
+   */
+  public static function formatLocaleNumeric(string $amount, $locale = NULL): string {
+    $formatter = new \NumberFormatter($locale ?? CRM_Core_I18n::getLocale(), NumberFormatter::DECIMAL);
+    $formatter->setSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, CRM_Core_Config::singleton()->monetaryDecimalPoint);
+    $formatter->setSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, CRM_Core_Config::singleton()->monetaryThousandSeparator);
+    return $formatter->format($amount);
+  }
+
 }