# NumberFormatOptions
Options to be passed into the constructor method.
NOTE
This is an abstract type. Any object of this structure can be used where this type is used.
# Properties
# currency
Set to the ISO 4217 currency code to use when formatting with the currency style.
If the <Global.Intl.NumberFormat.NumberFormatOptions.style> option is set to 'currency'
,
then you must also set this currency
option to an
ISO 4217 currency code
such as 'USD'
for US dollars or 'EUR'
for euros.
# currencyDisplay
Indicates how the currency symbol or name should be shown.
This option is only applicable if <Global.Intl.NumberFormat.NumberFormatOptions.style>
is set to 'currency'
.
This option can be set to one of the following:
'symbol'
Outputs the currency symbol such as'$'
for US dollars.'code'
Outputs the ISO 4217 currency code such as'USD'
or'EUR'
.'name'
Outputs the full currency name such as'US dollars'
.
Android ignores this option and will always display a currency symbol.
Default: symbol
# localeMatcher
The locale matching algorithm to use.
Can be set to 'lookup'
or 'best fit'
.
This option is ignored on Android.
Default: best fit
# maximumFractionDigits
Max number of fractional digits to be shown. Will round at this max digit.
A value ranging between 0
to 20
setting the maximum number of fractional digits
to be shown. Will round the number at this maximum.
const formatter = new Intl.NumberFormat(Ti.Locale.currentLocale, {
maximumFractionDigits: 3,
});
console.log(formatter.format(1.2345)); // Logs: 1.235
console.log(formatter.format(0.1)); // Logs: 0.1
console.log(formatter.format(1)); // Logs: 1
Default: 0
# maximumSignificantDigits
Max number of significant digits to be shown. Will round at this max digit.
A value ranging between 1
to 21
setting the maximum number of significant digits
to be shown. Will round the number at this maximum.
const formatter = new Intl.NumberFormat(Ti.Locale.currentLocale, {
maximumSignificantDigits: 3,
});
console.log(formatter.format(12345.6)); // Logs: 12300
console.log(formatter.format(1.23456)); // Logs: 1.23
console.log(formatter.format(0.0123456)); // Logs: 0.0123
Default: 21
# minimumFractionDigits
Applies trailing zeros in fractional portion of the formatted number.
A value ranging between 0
to 20
setting the minimum number of fractional digits
to be shown. This will pad the formatted number with trailing zeros if needed.
// Pad with 2 trailing zeros.
const formatter = new Intl.NumberFormat(Ti.Locale.currentLocale, {
minimumFractionDigits: 2,
});
console.log(formatter.format(123)); // Logs: 123.00
console.log(formatter.format(0.1)); // Logs: 0.10
console.log(formatter.format(0.123)); // Logs: 0.123
Default: 0
# minimumIntegerDigits
Applies leading zeros to the integer portion of the formatted number.
A value ranging between 0
to 21
setting the minimum number of integer digits to be shown
on the left side of the decimal separator. This will pad the formatted number with
leading zeros if the number of digits is below this minimum value.
// Pad with 3 leading zeros.
const formatter = new Intl.NumberFormat(Ti.Locale.currentLocale, {
minimumIntegerDigits: 3,
});
console.log(formatter.format(1)); // Logs: 001
console.log(formatter.format(12)); // Logs: 012
console.log(formatter.format(123)); // Logs: 123
console.log(formatter.format(1234)); // Logs: 1234
Set to 0
to not show any leading zeros.
// Do not pad with leading zeros.
const formatter = new Intl.NumberFormat(Ti.Locale.currentLocale, {
minimumIntegerDigits: 0,
});
console.log(formatter.format(1)); // Logs: 1
console.log(formatter.format(0)); // Logs: 0
console.log(formatter.format(0.5)); // Logs: .5
console.log(formatter.format(0.05)); // Logs: .05
Default: 1
# notation
Indicates if number should be formatted to scientific or engineering notation.
Can be set to one of the following:
'standard'
Format to a plain number such as'123456.7'
.'scientific'
Formats to scientific notation having only 1 integer digit such as'1.235E5'
.'engineering'
Formats to engineering notation where exponent is in increments of 3 such as'123.457E3'
.
This option is only supported on Android.
Default: standard
# style
Specifies the format style such as decimal, currency, or percentage.
Can be set to one of the following:
'decimal'
Formats as a floating point value such as'-1,234.5'
.'currency'
Formats value as a currency such as'$100'
. You must also set the <Global.Intl.NumberFormat.NumberFormatOptions.currency> option when using this style or else an exception will be thrown.'percent'
Multiplies value by 100 and formats as a percentage. For example, a value of1.0
will be formatted as'100%'
.
Note that Android and iOS do not support the 'unit'
style defined in the ECMA standard.
Default: decimal
# useGrouping
Indicates if grouping separators should be displayed.
When set true
, grouping separators will be displayed in the integer portion of the number
such as '1,234,567.8'
for English region formatted numbers.
Set false
to not show grouping separators such as 1234567.8
.
Default: true