DecimalFormatOptions
Object expressing options for decimal formatting methods.
Syntax
object { style?, negativeZero?, group?, round?, divisor?, minimumIntegerDigits?, maximumFractionDigits?, minimumFractionDigits?, maximumSignificantDigits?, minimumSignificantDigits?, nu?, errors?: NumberFormatErrorType[] }
Properties
style?: DecimalFormatStyleType
- Style used to format the number.
negativeZero?: boolean
- Format negative zero.
group?: boolean
- Enable grouping of digits.
round?: RoundingModeType
- Mode used to round numbers during formatting.
divisor?: number
- Specify an explicit divisor when formatting a compact style. Should be a round power of 10, e.g.
1000
,10000
, etc.
- Specify an explicit divisor when formatting a compact style. Should be a round power of 10, e.g.
minimumIntegerDigits?: number
- Minimum integer digits to display.
maximumFractionDigits?: number
- Maximum fraction digits to display.
minimumFractionDigits?: number
- Minimum fraction digits to display.
maximumSignificantDigits?: number
- Maximum significant digits to display.
minimumSignificantDigits?: number
- Minimum significant digits to display.
nu?: NumberSystemType
- Override the number system used to format the digits.
errors?: NumberFormatErrorType
- Optional flags controlling when formatting a
NaN
orInfinity
will raise an error
- Optional flags controlling when formatting a
Defaults
{
style: 'decimal',
negativeZero: false,
group: true,
round: 'half-even'
}
- Integer and fraction option defaults are determined by the selected number pattern.
- Options for significant digits default to
undefined
. - Numbering system default is determined by the locale.
- By default values
NaN
andInfinity
are formatted
Examples
const cldr = framework.get('en');
log(cldr.Numbers.formatDecimal('12345.6789', { group: true }));
12,345.679
Using a compact style with an explicit fixed divisor.
const opts = { style: 'long', divisor: 1000 };
log(cldr.Numbers.formatDecimal('100', opts));
log(cldr.Numbers.formatDecimal('1234567', opts));
0.1 thousand 1,235 thousand
Formatting negative zero.
const opts = { maximumFractionDigits: 0, round: 'down' };
log(cldr.Numbers.formatDecimal('-0.999', opts));
log(cldr.Numbers.formatDecimal('-0.999', { ...opts, negativeZero: true }));
0 -0