Jump to content

Module:FormatNumber/doc

From The Perfect Tower II
Revision as of 01:41, 7 October 2026 by Speedybrain (talk | contribs) (Documentation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:FormatNumber

Formats numbers as the game does. It backs {{Number}} and, through it, {{Cost}}. Module:UI (crafting cost) and Module:ModuleView (full view) call it directly.

Numbers below a million show in full, with thousands separators (120,000). Larger numbers show as scientific notation (1.2E7) or as named numbers (12 M); the reader picks under Appearance > Numbers, and scientific notation is the default. The module writes both forms, in span.wiki-num__sci and span.wiki-num__named, and MediaWiki:Common.css shows the one the reader picked. Each form has the other in its tooltip. The E is uppercase, as in the game, inside the brand kit class .tpt-num__e, which sets it smaller than the digits. Page previews (TextExtracts) leave out the named form. inf and Infinity show as Infinity.

Entry points

  • main(frame): for the template. It reads the arguments of the invoke, or else of the calling template: 1 (the number; thousands separators and 1e7 notation work, and anything that isn't a number comes back unchanged), format, prefix, suffix, sortkey, icon and iconpos. The result is wrapped in a span with data-sort-value, for sortable tables.
  • format(value, prefix, suffix, icon, iconPos, format): for other modules. value must be a number; it isn't checked. format set to named or scientific forces one form for every reader, with the other in an abbr tooltip. icon follows the number, or comes before it with iconPos = "left".
local formatNumber = require('Module:FormatNumber').format
formatNumber(1.8e12, nil, '%') -- 1.8E12% or 1.8 T%, as the reader chose