Formatter.Decimal (Decimal Formatter)

An instance of the Formatter.Decimal class (Decimal Formatter) is used to display numeric data. This formatter class formats and parses Decimal-valued strings, not Number values.

Here’s an example of creating a new Decimal instance from a Number:

New Decimal Object


// Decimal from Numeric String dVal = Decimal.fromString("12345") // Decimal from Number numericValue = 12345 dVal = Decimal.fromString(String(numericValue))

Decimal Formatter Class Properties

Here are the properties of the Formater.Decimal class:

Currency Codes Property (depricated)


Formatter.Decimal.currencyCodes //--> ["ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "EQE", "ERN", "ESA", "ESB", "ESP", "ETB", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LSM", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MRU", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZD", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"]

Using the currencyCode property of the Locale class to retrieve the currency code for Sweden:

Currency Code for Sweden


new Locale("sv_SE").currencyCode //--> "SEK"

Decimal Formatters

Decimal Formatters can be created in a variety of formatting styles:

Decimal Formatters


fmtr = Formatter.Decimal.custom fmtr = Formatter.Decimal.decimal fmtr = Formatter.Decimal.percent fmtr = Formatter.Decimal.percentWithDecimal fmtr = Formatter.Decimal.plain fmtr = Formatter.Decimal.thousandsAndDecimal
Decimal Formatter - Decimal


dVal = Decimal.fromString(String(12345.123)) fmtr = Formatter.Decimal.decimal fmtr.stringFromDecimal(dVal) //--> "12345.12"
Decimal Formatter - Plain


dVal = Decimal.fromString(String(12345.123)) fmtr = Formatter.Decimal.plain fmtr.stringFromDecimal(dVal) //--> "12345"
Decimal Formatter - Thousands and Decimal Separator


dVal = Decimal.fromString(String(12345.123)) fmtr = Formatter.Decimal.thousandsAndDecimal fmtr.stringFromDecimal(dVal) //--> "12,345.12"
Decimal Formatter - Custom


dVal = Decimal.fromString(String(12345.123)) fmtr = Formatter.Decimal.custom fmtr.decimalSeparator = "·" fmtr.thousandsSeparator = "’" fmtr.stringFromDecimal(dVal) //--> "12’345·12"
Decimal Formatter - Decimal Percentage


dVal = Decimal.fromString(String(123.123)) fmtr = Formatter.Decimal.percentWithDecimal fmtr.stringFromDecimal(dVal) //--> "123.12%"
Decimal Formatter - Percent


dVal = Decimal.fromString(String(123.123)) fmtr = Formatter.Decimal.percent fmtr.stringFromDecimal(dVal) //--> "123%"

Decimal Formatter Instance Properties

Here are the properties of an instance of the Formater.Decimal class:

Decimal Formatter Class Methods (functions)

Here are the methods (functions) of the Formater.Decimal class:

Number to Swedish Kroner


code = new Locale("sv_SE").currencyCode //--> "SEK" fmtr = Formatter.Decimal.currency(code) dVal = Decimal.fromString('12345') fmtr.stringFromDecimal(dVal) //--> SEK12,345.00

Decimal Formatter Instance Functions

Here are the methods (functions) of an instance of the Formater.Decimal class:

Percent Formatter


fmtr = Formatter.Decimal.percent dVal = Decimal.fromString('79') fmtr.stringFromDecimal(dVal) //--> 79%

Reference Links