X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FNumber.php;h=790fdd1278e233b90f54f94591226b5e065c0a80;hb=076fe09aa31cb92fa9e254b06a32e17ce5c76e4b;hp=3dae925661efe6b395d181f0055199a3f9f24253;hpb=c67d09e8bc2540a4e1a16019b8b4a2b3f16552f5;p=civicrm-core.git diff --git a/CRM/Utils/Number.php b/CRM/Utils/Number.php index 3dae925661..790fdd1278 100644 --- a/CRM/Utils/Number.php +++ b/CRM/Utils/Number.php @@ -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); + } + }