Dart - Formatting Currency with NumberFormat

If you have a number and you want to format it to currency of any locale, Dart makes it easy for us to do it by using NumberFormat class.

Currently, Dart already supports hundreds of locales, listed at the bottom of this tutorial.

There are two methods in NumbeFormat built specifically for currency formatting: NumberFormat.currency and NumberFormat.simpleCurrency. The difference between those two methods is the first one uses the locale's CURRENCY_PATTERN, while the latter uses simple symbol such as $, £, €, and Rp.

Below are the list of options for those two methods. Keep in mind that symbol and customPattern are not supported by .simpleCurrency

Option Type Description
locale String The locale to be used If not passed, it will use default locale.
name String If passed, it will be used as the currency name.
symbol* String If passed, the formatted number will use the symbol instead of name.
decimalDigits int If specified, it sets how many decimal digits in the formatted output. If it's not specified and the name is defined, it will use the default for the name. Otherwise, it will use the default for the currency.
customPattern* String It can be used to define custom pattern.

Using NumberFormat.currency

  // A1
  print(NumberFormat.currency().format(123456)); // USD123,456.00

  // A2
  print(NumberFormat.currency(locale: 'eu').format(123456)); // 123.456,00 EUR

  // A3
  print(NumberFormat.currency(name: 'EURO').format(123456)); // EURO123,456.00

  // A4
  print(NumberFormat.currency(locale: 'eu', symbol: '?').format(123456)); // 123.456,00 ?

  // A5
  print(NumberFormat.currency(locale: 'eu', decimalDigits: 3).format(123456)); // 123.456,000 EUR

  // A6
  print(NumberFormat.currency(locale: 'eu', customPattern: '\u00a4 #,##.#').format(123456)); // EUR 12.34.56,00

In the example A1, no locale is set and therefore it uses the systemLocale whose default value is en_US. It's not automatically set unless you call findSystemLocale by importing intl_browser.dart or intl_standalone.dart depending on where the application runs. You can see that the result uses en_US locale.

In the example A2, the locale is set to eu. You can see that the result is formatted to European from the presence of 'EUR' keyword at the end and the opposite use of . (dot) and , (comma).

The third example A3 only passes name option, which means the default locale is used. It only replaces 'USD' with 'EURO'.

The example A4 uses eu as the locale and ? as the symbol replacing name.

The example A5 set decimalDigits to specify the number of decimal digits.

The example A6 uses customPattern. The \u00a4 part is the unicode character of currency sign, while the pattern #,##.# means every two digits will be separated by separator (instead of every three digits).

*: Not supported by .simpleCurrency

Using NumberFormat.simpleCurrency

Using this method, by default you will get the symbol instead of the name of the currency. You can see the symbol mapping at bottom of this example.

  # B1
  print(NumberFormat.simpleCurrency().format(123456)); // $123,456.00

  # B2
  print(NumberFormat.simpleCurrency(locale: 'eu').format(123456)); // 123.456,00 €

  # B3
  print(NumberFormat.simpleCurrency(name: 'EURO').format(123456)); // EURO123,456.00

  # B4
  print(NumberFormat.simpleCurrency(locale: 'eu', decimalDigits: 3).format(123456)); // 123.456,000 €

The example B1 doesn't set the locale, so it will use the default locale as explained on .currency method section. From the result, you can see that it uses the $ symbol instead of the currency name.

In the example B2, locale is set to eu. You'll get the European formatted currency with € symbol.

In the example B3, by passing name, it replaces the usage of symbol.

The last example B4 sets number of decimal digits in the output.

List of Supported Locales

Here's the list of supported locales. If you try to use non-supported locale, you will get Invalid argument exception.

  • af: ZAR
  • am: ETB
  • ar: EGP
  • ar_DZ: DZD
  • ar_EG: EGP
  • az: AZN
  • be: BYN
  • bg: BGN
  • bn: BDT
  • br: EUR
  • bs: BAM
  • ca: EUR
  • chr: USD
  • cs: CZK
  • cy: GBP
  • da: DKK
  • de: EUR
  • de_AT: EUR
  • de_CH: CHF
  • el: EUR
  • en: USD
  • en_AU: AUD
  • en_CA: CAD
  • en_GB: GBP
  • en_IE: EUR
  • en_IN: INR
  • en_MY: MYR
  • en_SG: SGD
  • en_US: USD
  • en_ZA: ZAR
  • es: EUR
  • es_419: MXN
  • es_ES: EUR
  • es_MX: MXN
  • es_US: USD
  • et: EUR
  • eu: EUR
  • fa: IRR
  • fi: EUR
  • fil: PHP
  • fr: EUR
  • fr_CA: CAD
  • fr_CH: CHF
  • ga: EUR
  • gl: EUR
  • gsw: CHF
  • gu: INR
  • haw: USD
  • he: ILS
  • hi: INR
  • hr: HRK
  • hu: HUF
  • hy: AMD
  • id: IDR
  • in: IDR
  • is: ISK
  • it: EUR
  • it_CH: CHF
  • iw: ILS
  • ja: JPY
  • ka: GEL
  • kk: KZT
  • km: KHR
  • kn: INR
  • ko: KRW
  • ky: KGS
  • ln: CDF
  • lo: LAK
  • lt: EUR
  • lv: EUR
  • mk: MKD
  • ml: INR
  • mn: MNT
  • mr: INR
  • ms: MYR
  • mt: EUR
  • my: MMK
  • nb: NOK
  • ne: NPR
  • nl: EUR
  • no: NOK
  • no_NO: NOK
  • or: INR
  • pa: INR
  • pl: PLN
  • ps: AFN
  • pt: BRL
  • pt_BR: BRL
  • pt_PT: EUR
  • ro: RON
  • ru: RUB
  • si: LKR
  • sk: EUR
  • sl: EUR
  • sq: ALL
  • sr: RSD
  • sr_Latn: RSD
  • sv: SEK
  • sw: TZS
  • ta: INR
  • te: INR
  • th: THB
  • tl: PHP
  • tr: TRY
  • uk: UAH
  • ur: PKR
  • uz: UZS
  • vi: VND
  • zh: CNY
  • zh_CN: CNY
  • zh_HK: HKD
  • zh_TW: TWD
  • zu: ZAR

Mapping to Simple Currencies

  • AFN: Af.
  • TOP": r"T$
  • MGA: Ar
  • THB: \u0e3f
  • PAB: B/.
  • ETB: Birr
  • VEF: Bs
  • BOB: Bs
  • GHS: GHS
  • CRC: \u20a1
  • NIO": r"C$
  • GMD: GMD
  • MKD: din
  • BHD: din
  • DZD: din
  • IQD: din
  • JOD: din
  • KWD: din
  • LYD: din
  • RSD: din
  • TND: din
  • AED: dh
  • MAD: dh
  • STD: Db
  • BSD": r"$
  • FJD": r"$
  • GYD": r"$
  • KYD": r"$
  • LRD": r"$
  • SBD": r"$
  • SRD": r"$
  • AUD": r"$
  • BBD": r"$
  • BMD": r"$
  • BND": r"$
  • BZD": r"$
  • CAD": r"$
  • HKD": r"$
  • JMD": r"$
  • NAD": r"$
  • NZD": r"$
  • SGD": r"$
  • TTD": r"$
  • TWD": r"NT$
  • USD": r"$
  • XCD": r"$
  • VND: \u20ab
  • AMD: Dram
  • CVE: CVE
  • EUR: \u20ac
  • AWG: Afl.
  • HUF: Ft
  • BIF: FBu
  • CDF: FrCD
  • CHF: CHF
  • DJF: Fdj
  • GNF: FG
  • RWF: RF
  • XOF: CFA
  • XPF: FCFP
  • KMF: CF
  • XAF: FCFA
  • HTG: HTG
  • PYG: Gs
  • UAH: \u20b4
  • PGK: PGK
  • LAK: \u20ad
  • CZK: K\u010d
  • SEK: kr
  • ISK: kr
  • DKK: kr
  • NOK: kr
  • HRK: kn
  • MWK: MWK
  • ZMK: ZWK
  • AOA: Kz
  • MMK: K
  • GEL: GEL
  • LVL: Ls
  • ALL: Lek
  • HNL: L
  • SLL: SLL
  • MDL: MDL
  • RON: RON
  • BGN: lev
  • SZL: SZL
  • TRY: TL
  • LTL: Lt
  • LSL: LSL
  • AZN: man.
  • BAM: KM
  • MZN: MTn
  • NGN: \u20a6
  • ERN: Nfk
  • BTN: Nu.
  • MRO: MRO
  • MOP: MOP
  • CUP": r"$
  • CUC": r"$
  • ARS": r"$
  • CLF: UF
  • CLP": r"$
  • COP": r"$
  • DOP": r"$
  • MXN": r"$
  • PHP: \u20b1
  • UYU": r"$
  • FKP: £
  • GIP: £
  • SHP: £
  • EGP: E£
  • LBP: L£
  • SDG: SDG
  • SSP: SSP
  • GBP: £
  • SYP: £
  • BWP: P
  • GTQ: Q
  • ZAR: R
  • BRL": r"R$
  • OMR: Rial
  • QAR: Rial
  • YER: Rial
  • IRR: Rial
  • KHR: Riel
  • MYR: RM
  • SAR: Riyal
  • BYR: BYR
  • RUB: руб.
  • MUR: Rs
  • SCR: SCR
  • LKR: Rs
  • NPR: Rs
  • INR: \u20b9
  • PKR: Rs
  • IDR: Rp
  • ILS: \u20aa
  • KES: Ksh
  • SOS: SOS
  • TZS: TSh
  • UGX: UGX
  • PEN: S/.
  • KGS: KGS
  • UZS: so\u02bcm
  • TJS: Som
  • BDT: \u09f3
  • WST: WST
  • KZT: \u20b8
  • MNT: \u20ae
  • VUV: VUV
  • KPW: \u20a9
  • KRW: \u20a9
  • JPY: ¥
  • CNY: ¥
  • PLN: z\u0142
  • MVR: Rf
  • NLG: NAf
  • ZMW: ZK
  • ANG: ƒ
  • TMT: TMT