# Number Formatting ## Basic Usage You can localize the number with your definition formats. Number formats the below: ```js const numberFormats = { 'en-US': { currency: { style: 'currency', currency: 'USD', notation: 'standard' }, decimal: { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }, percent: { style: 'percent', useGrouping: false } }, 'ja-JP': { currency: { style: 'currency', currency: 'JPY', useGrouping: true, currencyDisplay: 'symbol' }, decimal: { style: 'decimal', minimumSignificantDigits: 3, maximumSignificantDigits: 5 }, percent: { style: 'percent', useGrouping: false } } } ``` As the above, you can define named number formats (e.g. `currency`, etc), and you need to use [the options with ECMA-402 Intl.NumberFormat](https://tc39.es/ecma402/#numberformat-objects) After that, when using the locale messages, you need to specify the `numberFormats` option of `createI18n`: ```js const i18n = createI18n({ numberFormats }) ``` To localize Number value with Vue I18n, use the `$n` (via global injection) or `n` from `useI18n()`. > [!TIP] > `$n` has some overloads. About these overloads, see the [API Reference](../../api/vue/interfaces/ComponentCustomProperties.md#n) The following is an example of the use of `$n` in a template: ```html
{{ $n(10000, 'currency') }}
{{ $n(10000, 'currency', 'ja-JP') }}
{{ $n(10000, 'currency', 'ja-JP', { useGrouping: false }) }}
{{ $n(987654321, 'currency', { notation: 'compact' }) }}
{{ $n(0.99123, 'percent') }}
{{ $n(0.99123, 'percent', { minimumFractionDigits: 2 }) }}
{{ $n(12.11612345, 'decimal') }}
{{ $n(12145281111, 'decimal', 'ja-JP') }}
``` The first argument is numeric value as a parameter, and the second argument is number format name as a parameter. The last argument locale value as a parameter. As result the below: ```html$10,000.00
¥10,000
¥10000
$988M
99%
99.12%
12.12
12,145,000,000
``` ## Usage in `{{ n(10000, 'currency') }}
{{ n(10000, 'currency', 'ja-JP') }}
``` For more advanced usage, see the [Composition API guide](../advanced/composition.md). ## Custom Formatting `$n` returns resulting string with fully formatted number, which can only be used as a whole. In situations when you need to style some part of the formatted number (like fraction digits), `$n` is not enough. In such cases NumberFormat component (`i18n-n`) will be of help. With a minimum set of properties, `i18n-n` generates the same output as `$n`, wrapped into configured DOM element. The following template: ```html