3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Add thousands separator to numeric strings using
22 * PHP number_format() function.
24 * @param float $number
25 * Numeric value to be formatted.
26 * @param int $decimals
27 * Number of decimal places.
28 * @param string $dec_point
29 * Decimal point character (if other than ".").
30 * @param string $thousands_sep
31 * Thousands sep character (if other than ",").
34 * the formatted string
36 * For alternate decimal point and thousands separator, delimit values with single quotes in the template.
37 * EXAMPLE: {$number|crmNumberFormat:2:',':' '} for French notation - 1234.56 becomes 1 234,56
39 function smarty_modifier_crmNumberFormat($number, $decimals = NULL, $dec_point = NULL, $thousands_sep = NULL) {
40 if (is_numeric($number)) {
41 // Both dec_point AND thousands_sep are required if one is not specified
42 // then use the config defaults
43 if (!$dec_point ||
!$thousands_sep) {
44 $config = CRM_Core_Config
::singleton();
45 $dec_point = $config->monetaryDecimalPoint
;
46 $thousands_sep = $config->monetaryThousandSeparator
;
49 return number_format($number, $decimals, $dec_point, $thousands_sep);