API Reference › Decimal
namespace

Decimal

Exact base-10 fixed-point numbers for game economies — prices, balances and taxes on values like 0.10 that binary floating point cannot represent, so they always add up exactly. A Decimal is a BigInt mantissa with a decimal scale (the number of digits after the point), giving unbounded range and exact add / sub / mul. Build one with Decimal.from (an int) or Decimal.parse (text like "19.99"), compare with cmp / eq, change precision with rescale (truncates toward zero), read the current precision with scale, and render with str. Every operation is exact and deterministic. The runtime is spliced in only when a program mentions Decimal.* (or BigInt.*).

Decimal.from(value) -> DecimalTurn a whole int into a Decimal.Decimal.parse(text) -> DecimalParse decimal text like "19.99".Decimal.add(a, b) -> DecimalExact sum of two decimals.Decimal.sub(a, b) -> DecimalExact difference of two decimals.Decimal.mul(a, b) -> DecimalExact product of two decimals.Decimal.neg(a) -> DecimalNegate a decimal.Decimal.cmp(a, b) -> intCompare two decimals: -1, 0, or 1.Decimal.eq(a, b) -> boolTrue when two decimals are equal in value.Decimal.scale(d) -> intThe number of digits after the point.Decimal.rescale(d, places) -> DecimalChange precision (truncates toward zero).Decimal.str(d) -> stringRender a decimal as text.
← All symbols