Phaser AE

Enormous decimal values

Free packv3.0.0-4Logic

Decimal arithmetic for huge game currencies, prices and production. Values keep forty significant digits and an exponent up to a billion, and never pass through a JavaScript number that would overflow or lose digits.

This is a Free pack. Every phaser.io account can use it in their games.

Released October 14, 2026 · updated October 20, 2026

Enormous decimal values: a screenshot of its demo
A note about these graphics

Expansion packs don't come with graphics. This screenshot is one way of drawing what the pack does, made for its demo: none of the sprites, tiles or backgrounds in it are in the pack.

That's by design. A pack is a game's logic, mechanics and effects, and it works with whatever art you give it. Some packs draw effects, backdrops or 3D scenes of their own, but none carries a game's sprites.

So the look is yours. Make the art on phaser.io, bring your own, or let your agent draw it in code: the same pack can look like anything.

The pack

largeNumbers

function largeNumbers(): Pack<{ largeNumbers: typeof rules }>

Install renderer-independent enormous decimal arithmetic and formatting.

Helpers

formatLarge

function formatLarge(input: LargeInput, options: LargeFormatOptions = {}): string

Human-readable rounding with suffix rollover; values beyond named suffixes use engineering notation.

largeNumber

function largeNumber(value: LargeInput = 0): LargeNumber

Convenient public constructor.

largeNumberScales

const largeNumberScales: ReadonlyArray<Readonly<{ name: string; exponent: number; abbreviation: string }>>

Recognized short-scale names; gaps beyond vigintillion fall back to scientific notation.

Classes

LargeNumber

class LargeNumber

Immutable, JSON-safe forty-significant-digit decimals with compressed enormous exponents.

  • readonly coefficient: string — Signed integer coefficient stored as text so snapshots need no BigInt JSON support.
  • readonly exponent: number — Value is coefficient times ten raised to this exponent.
  • constructor(value: LargeInput = 0, rounding: LargeRounding = 'half-even')
  • static from(value: LargeInput): LargeNumber — Parse without converting decimal text through a JavaScript number.
  • get sign(): -1 | 0 | 1 — Sign, including a canonical unsigned zero.
  • compare(input: LargeInput): -1 | 0 | 1 — Exact comparison of the retained decimal values.
  • add(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber — Add with bounded exponent alignment and an explicit rounding policy.
  • subtract(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber — Subtract; floor rounding is useful for conservative nonnegative currency spending.
  • multiply(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber — Multiply without ordinary-number overflow.
  • divide(input: LargeInput, rounding: LargeRounding = 'half-even'): LargeNumber — Divide with guard digits and sticky remainder; zero denominators fail explicitly.
  • pow(exponent: number, rounding: LargeRounding = 'half-even'): LargeNumber — Integer exponentiation by squaring, bounded to one million in either direction.
  • sqrt(rounding: LargeRounding = 'half-even'): LargeNumber — Nonnegative square root with decimal guard digits, without converting the magnitude to Number.
  • negate(): LargeNumber — Return the opposite sign.
  • abs(): LargeNumber — Return the nonnegative magnitude.
  • round(places = 0, rounding: LargeRounding = 'half-even'): LargeNumber — Round to decimal places; negative places round to tens, billions and beyond.
  • toNumber(): number — Approximate ordinary number conversion for bounded ratios/UI only; throws on overflow/underflow.
  • toString(): string — Canonical scientific decimal text, preserving every retained digit.
  • toJSON(): string — JSON serialization stores decimal text, never an overflowing Number or a raw BigInt.
  • format(options: LargeFormatOptions = {}): string — Format compact, named, scientific, engineering or bounded plain output.

Constants

LARGE_NUMBER_MAX_EXPONENT

const LARGE_NUMBER_MAX_EXPONENT: 1000000000

Maximum absolute base-ten order of magnitude; arithmetic fails explicitly outside it.

LARGE_NUMBER_PRECISION

const LARGE_NUMBER_PRECISION: 40

Decimal significant digits retained by every arithmetic operation.

Types

LargeFormatOptions

interface LargeFormatOptions

Readable output with bounded size; formatting never changes the numeric value.

  • notation?: 'compact' | 'named' | 'scientific' | 'engineering' | 'plain' — Default compact: K/M/B/T and named larger suffixes, then engineering notation.
  • significantDigits?: number — One to forty significant digits; default four.

LargeInput

type LargeInput = LargeNumber | string | number | bigint | { coefficient: string; exponent: number }

Exact decimal text, a safe ordinary numeric input, or a canonical decimal pair.

LargeRounding

type LargeRounding = 'half-even' | 'floor' | 'ceil' | 'trunc'

Round ties to even, toward negative/positive infinity, or toward zero.