Module:FormatNumber/doc
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 and1e7notation work, and anything that isn't a number comes back unchanged),format,prefix,suffix,sortkey,iconandiconpos. The result is wrapped in a span withdata-sort-value, for sortable tables.format(value, prefix, suffix, icon, iconPos, format): for other modules.valuemust be a number; it isn't checked.formatset tonamedorscientificforces one form for every reader, with the other in anabbrtooltip.iconfollows the number, or comes before it withiconPos = "left".
local formatNumber = require('Module:FormatNumber').format
formatNumber(1.8e12, nil, '%') -- 1.8E12% or 1.8 T%, as the reader chose