numbers
In Filters
Locale-aware number-formatting filters built on Intl.NumberFormat.
import {
number,
currency,
percent,
} from '@allons-y/dashly/filters/numbers';
number(value, options?, locale?)
Format a number using Intl.NumberFormat. Returns an empty string for
non-numeric input so templates render gracefully.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
number | string |
||
options
(optional)
|
Intl.NumberFormatOptions |
||
locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
Returns
string
Examples
// '1,234,567'
number(1234567);
// '1 234 567,89'
number(1234567.89, { maximumFractionDigits: 2 }, 'fr-FR');
{{ stats.views | number }}
currency(value, currencyCode?, locale?, options?)
Format a number as a localized currency string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
number | string |
||
currencyCode
(optional)
|
string |
'USD' |
ISO 4217 currency code. |
locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
|
options
(optional)
|
Intl.NumberFormatOptions |
Extra Intl.NumberFormat options. |
Returns
string
Examples
// '$1,299.00'
currency(1299);
// '1 299,00 €'
currency(1299, 'EUR', 'fr-FR');
{{ product.price | currency('USD') }}
percent(value, options?)
Format a number as a localized percentage. Input is treated as a fraction by
default (0.25 → 25%); pass { asFraction: false } to format whole-number
percentages (25 → 25%).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
number | string |
||
options
(optional)
|
object |
||
options.asFraction
(optional)
|
boolean |
true |
Treat input as a 0–1 fraction. Set false for whole-number percentages. |
options.maximumFractionDigits
(optional)
|
number |
0 |
|
options.locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
Returns
string
Examples
// '25%'
percent(0.25);
// '25%'
percent(25, { asFraction: false });
// '25.5%'
percent(0.255, { maximumFractionDigits: 1 });
{{ survey.completionRate | percent }}