Interface FormatOptions

Options used by toFixed to format a BigAmount as decimal.

Example

let f = BigAmount.create("123456789/10");
f.toFixed(2); // "12345678.90"
f.toFixed(2, { decimalSeparator: "," }); // "12345678,90"
f.toFixed(2, { groupSeparator: "," }); // "12,345,678.90"
f.neg().toFixed(2, {
decimalSeparator: ",",
groupSeparator: " ",
templates: ["{} €"],
}); // "-12 345 678,90 €"

const opts = { templates: ["${}", "$({})", "-"] };
BigAmount.create("123.45").toFixed(2, opts); // "$123.45"
BigAmount.create("-678.9").toFixed(2, opts); // "$(678.90)"
BigAmount.create("0").toFixed(2, opts); // "-"

Hierarchy

  • FormatOptions

Properties

decimalSeparator?: string

[Default: "."] Character used to separate the integer part from the fractional part.

experimentalUseLakhCrore?: boolean

[Default: false] Experimental. Use Indian 2,2,3 digit grouping rule (e.g. "1,00,00,000") instead of the three digit system. This option has to be used in conjunction with the groupSeparator option.

groupSeparator?: string

[Default: ""] Delimiter used to separate the groups of thousands (three digits) of the integer part. Grouping is disabled by default; give ",", ".", " ", or any other delimiter to enable grouping.

templates?: [string, string?, string?]

[Default: ["{}"]] Tuple of template strings used to format [positive numbers, negative numbers, zero], respectively. "{}" in a template string is replaced with the resulting string. The template for zero defaults to the template for positive numbers and the template for negative numbers defaults to the template for positive numbers with the prefix "-", if omitted. This option is convenient to decorate the resulting string with a currency symbol and/or negative parenstheses. See the above example for usage.

Generated using TypeDoc