Docs / Language & functions
a9script authoring pack — numbers functions
The numbers functions, with their arguments and a line of real script each. Called by bare name; nothing is imported. A call marked pauses does real work outside the script: the run is saved, and continues on the next line with the result.
formatNumber(value, options?) — pauses
Writes a number the way a reader in a given country expects — grouped thousands, the right decimal mark, as many decimals as you ask for.
value(number) — The number to write. It must be finite.options(object, optional) —{ locale, minimumFractionDigits, maximumFractionDigits }.localeis a language tag such asen-USorde-DEand defaults toen-US— stated, never taken from the machine, so the same script writes the same number everywhere. Any other option is refused by name.
Answers: The formatted text.
log(formatNumber(1234.5, { locale: "de-DE" })); // 1.234,5
formatCurrency(value, currency, options?) — pauses
Writes an amount of money: the symbol where that country puts it, and the number of decimals the currency itself uses — two for dollars and euros, none for yen.
value(number) — The amount. It must be finite.currency(string) — A three-letter currency code such asUSD,EURorJPY.options(object, optional) — The same optionsformatNumbertakes, with the sameen-USdefault when no locale is given.
Answers: The formatted text.
const total = input.event.body.items[0].price;
log(formatCurrency(total, "EUR", { locale: "de-DE" }));