Currency Formatter
CurrencyFormatter centralizes real money formatting across the game. It's globally accessible via System.formatter property.
formatValue
Formats a numeric value into a currency string using the current precision, separator, and symbol placement. Optional flags could be used to add the currency symbol and spacing.
formatValue(value:number, withCurrency:boolean = false, withSpace:boolean = false):string
const formatter = System.formatter;
formatter.currencyPlace = CurrencyPlace.PREFIX;
formatter.commaSeparator = true;
formatter.currency = '$';
const grandPrize = formatter.formatValue(1500000.4, true, true);
console.log(grandPrize);
// Output: $ 1,500,000.40
const currentWin = formatter.formatValue(45.5, true);
console.log(currentWin);
// Output: $45.50
roundValue
Rounds a numeric value using the configured precision multiplier.
roundValue(value:number):number
const formatter = System.formatter;
formatter.currencyPrecision = 2;
const roundedJackpot = formatter.roundValue(1500000.456);
console.log(roundedJackpot);
// Output: 1500000.46
currencyPrecision
Controls both the displayed decimal digits for the formatted string and the rounding multiplier.
set currencyPrecision(value:number)
get currencyPrecision():number
const formatter = System.formatter;
const defaultPrecision = formatter.roundValue(12.3456);
console.log(defaultPrecision);
// Output: 12.34
formatter.currencyPrecision = 3;
const higherPrecision = formatter.roundValue(12.3456);
console.log(higherPrecision);
// Output: 12.346
currencyPlace
Controls whether the currency symbol is prefixed or suffixed.
CurrencyPlace.PREFIX– Places the currency symbol before the numerical value (e.g., $100).CurrencyPlace.SUFFIX– Places the currency symbol after the numerical value (e.g., 100€).
set currencyPlace(value:CurrencyPlace)
get currencyPlace():CurrencyPlace
const formatter = System.formatter;
formatter.currencyPlace = CurrencyPlace.SUFFIX;
formatter.currency = '€';
const balance = formatter.formatValue(120.5, true, true);
console.log(balance);
// Output: 120.50 €
commaSeparator
Toggles thousand separators for the formatted string without affecting rounding.
set commaSeparator(value:boolean)
get commaSeparator():boolean
const formatter = System.formatter;
formatter.commaSeparator = true;
const balance = formatter.formatValue(2500000, true);
console.log(balance);
// Output: 2,500,000.00
currency
Controls the active currency symbol for the formatted string.
set currency(value:string)
get currency():string
const formatter = System.formatter;
formatter.currency = '€';
const balance = formatter.formatValue(3200000, true);
console.log(balance);
// Output: €3200000.00