Bước tới nội dung

Bản mẫu:D

Từ Capsach

This is the source of the wiki page Template:D.

THE derived twin of Template:C (derived-number provenance, 2026-08-27). A primary number carries an ink-anchored token id and renders as ; a derived number (a market share, a CAGR, a rank — computed by an article builder, not printed in any source) renders as , carrying not an id but a formula alias. The alias content-addresses the number's Excel formula over the primary ids it was computed from; the formula lives in the citing article's Data:<page id>.formulas.json intern file.

Like , it PRINTS only its value ({{{1}}}) — the alias is provenance, invisible to a reader. The click-to-source gadget (MediaWiki:Gadget-figureSource.js) paints the resolvable ones with a dotted gray underline (primary numbers get a solid one: solid = ink, dotted = calculated) and opens Bot:Formula on click, decomposing the number into its lettered components — each traceable, in turn, to source ink.

Usage:

 13.2            a derived value + its formula alias
 13.2    … rendered through a house format

Rendering (the hybrid, 2026-09-07). The four house formats that cover almost every cell on an article page — 0, 0.0, 0.00 and #,##0 — are rendered NATIVELY: the value prints as it is, or through formatnum for the grouped integer (an #ifexpr keeps the ASCII minus the module prints, and #iferror sends a non-numeric value to the module). Every other format goes to Module:Numfmt, the one implementation of the full grammar (rounding, sections, percent literals). The native path is correct ONLY because a token's value is CANONICAL and already QUANTIZED to its format's decimals — the mint's contract (numfmt.canonical_number, enforced for by formulalib.d_token) — so it never rounds and never pads. Why: each #invoke costs ~0.3 ms of Lua against the wiki's 7 s per-page limit; a 22-year ranking family is ~24k tokens. Measured on 4,000 cells: the previous body 2.6 s CPU (1.2 s of it Lua), the hybrid 1.2 s CPU and no Lua, byte-identical output (py -m tools.wiki.numfmt_check proves it on a fixture, before a deploy from the local source and after it against the live template). Pitfall: #switch compares numeric-looking case labels as NUMBERS, so 0, 0.0 and 0.00 are ONE case here — fine while they share a result; never give them different ones.

The alias shape is <page id>-<f|ft>-<hash>: the middle field is the KIND — f durable, ft temporary (an edition-bound span such as a CAGR or Change column, whose framing a later edition supersedes; the value stays true, the mark warns against reuse as "current"). tabindex is the load-bearing iOS detail (a focusable element passes Safari's "clickable" heuristic).

The plain value follows a <nowiki/> (2026-10-02): MediaWiki starts a new line before parser-function output that begins with #, *, : or ;, so a value such as "# of replies" rendered as a numbered list beside an empty token span.