Money Formatter

The MoneyFormatter class makes it easy to create human-readable representions of money values in WoW.

Foramts

The following formats can be set via the :SetFormat() method. They are available via the MoneyFormatter.FORMAT enum.

  • MoneyFormatter.FORMAT.TEXT - Use colored “g”/”s”/”c” text strings for denominations.

  • MoneyFormatter.FORMAT.TEXT_DISABLED - Use colored (with a disabled tint) “g”/”s”/”c” text strings for denominations.

  • MoneyFormatter.FORMAT.ICON - Use gold/silver/copper texture icons.

  • MoneyFormatter.FORMAT.TEXT_DISABLED - Use gold/silver/copper texture icons with a disabled tint.

Copper Handling

In many situations, the copper values is not worth displaying. The following behaviors are made available via the MoneyFormatter.COPPER_HANDLING enum and can be set via the :SetCopperHandling() method.

  • MoneyFormatter.COPPER_HANDLING.KEEP - Always display the copper value.

  • MoneyFormatter.COPPER_HANDLING.ROUND_OVER_1G - Round to the nearest silver if the value is greater than 1 gold. Also removes the copper value if it’s 0.

  • MoneyFormatter.COPPER_HANDLING.REMOVE - Always remove the copper value.

API

class MoneyFormatter: Class
staticmethod New(): MoneyFormatter

Creates a new money formatter.

staticmethod SetLargeNumberSeperator(value: string)

Sets the large number seperator.

Parameters:

value (string) – The string value

staticmethod GetLargeNumberSeperator(): string

Gets the large number seperator.

staticmethod GetCopperText(): string

Returns the colored copper indicator text.

staticmethod GetSilverText(): string

Returns the colored silver indicator text.

staticmethod GetGoldText(): string

Returns the colored gold indicator text.

staticmethod FromString(value: string): number?

Converts a string money value to a number value (in copper).

The value passed to this function can contain colored text, but must use text and not icon tokens.

Parameters:

value (string) – The money value to be converted

SetFormat(self: MoneyFormatter, format: EnumValue): MoneyFormatter

Sets the format.

Parameters:

format (EnumValue) – The format to use

SetCopperHandling(self: MoneyFormatter, handling: EnumValue): MoneyFormatter

Changes how copper is handled.

Parameters:

handling (EnumValue) – How to handle copper

SetColor(self: MoneyFormatter, colorPrefix?: string): MoneyFormatter

Sets a color prefix to use for the text components.

Parameters:

colorPrefix? (string) – The color prefix string or nil to remove coloring

SetTrimEnabled(self: MoneyFormatter, enabled: boolean): MoneyFormatter

Sets whether or not trailing 0 values should be trimmed.

Parameters:

enabled (boolean) – Whether or not trimming should be enabled

ToString(self: MoneyFormatter, value: number): string

Converts a money value to a string.

Parameters:

value (number) – The value in copper