Difference between revisions of "User:Tumbolisu/Sandbox"
GrampaSwood (talk | contribs) m (mc) |
(Various cleanups to the formatting, but the primary fix was 100% correct.) |
||
Line 1: | Line 1: | ||
− | { | + | <!-- This template creates a subtable with two columns, the left column contains the integer part, and the right column contains the decimal. --> |
− | + | <includeonly> | |
− | + | {| class="nopad" width="100%" | |
− | + | | align="right" width="50%" style="border: 0 none; padding: 0; {{#switch:{{lc:{{{FORMAT|}}}}}|b=font-weight: bold;|i=font-style: italic;|bi|ib=font-weight: bold; font-style: italic;}}" | {{#if:{{{TOOLTIP|}}}|<span id="tooltip" style="cursor:help;border-bottom:1px dotted;" title="{{{TOOLTIP}}}">}}<!-- | |
− | {{#expr: trunc((({{{NUM|1}}} - trunc {{{NUM|1}}}) round {{{P|3}}}) e {{{P|3}}}) | + | In the left cell, right-aligned, we place the integer part: |
− | }}|{{{P|3}}}}}{{{POSTFIX|}}}{{#if:{{{TOOLTIP|}}}|</span>}} | + | -->{{#expr: trunc({{{NUM|1}}}) }}<!-- |
− | + | -->{{#if:{{{TOOLTIP|}}}|</span>}} | |
− | + | | align="left" width="50%" style="border: 0 none; padding: 0; {{#switch:{{lc:{{{FORMAT|}}}}}|b=font-weight: bold;|i=font-style: italic;|bi|ib=font-weight: bold; font-style: italic;}}" | {{#if:{{{TOOLTIP|}}}|<span id="tooltip" style="cursor:help;border-bottom:1px dotted;" title="{{{TOOLTIP}}}">}}<!-- | |
+ | In the right cell, left-aligned, we place the decimal part: | ||
+ | -->{{#ifeq: {{{P|3}}} | 0 | ||
+ | <!-- No padding, omit decimal part --> | ||
+ | | {{ns:0}} | ||
+ | <!-- Else, compute decimal part as an integer with round(num - floor(num), P) * 10^P --> | ||
+ | | {{dec}}{{padleft:{{#expr: trunc((({{{NUM|1}}} - trunc {{{NUM|1}}}) round {{{P|3}}}) e {{{P|3}}})}}|{{{P|3}}}}} | ||
+ | }}{{{POSTFIX|}}}{{#if:{{{TOOLTIP|}}}|</span>}} | ||
+ | |}</includeonly><noinclude> | ||
+ | {{clr}} | ||
{{Documentation}} | {{Documentation}} | ||
[[:Category:Formatting templates|{{PAGENAME}}]] | [[:Category:Formatting templates|{{PAGENAME}}]] | ||
</noinclude> | </noinclude> |
Latest revision as of 05:00, 2 June 2023
This template is useful for stacking values in a table, where the numbers should be aligned based on the decimal separator. This template takes three arguments:
Argument | Meaning |
---|---|
NUM | Number to format |
P | Number of places after the decimal separator, defaults to three. |
POSTFIX | String to append to the end of the number, such as a % symbol.
|
FORMAT | B for Bold, I for Italic, and BI or IB for Bold Italic |
TOOLTIP | Hover tooltip for the entire number, including POSTFIX if present. |
So in example, the following table construct:
{| class="wikitable grid" |- ! class = "header" | Numbers |- | {{User:Tumbolisu/Sandbox | NUM = 123.456789}} |- | {{User:Tumbolisu/Sandbox | NUM = 123.456789 | P = 0}} |- | {{User:Tumbolisu/Sandbox | NUM = 123}} |- | {{User:Tumbolisu/Sandbox | NUM = {{#expr: 24 * 6 /11}}}} |- | {{User:Tumbolisu/Sandbox | NUM = 999.1111 | P = 2}} |- | {{User:Tumbolisu/Sandbox | NUM = 33.343 | POSTFIX = % | FORMAT = I}} |- | {{User:Tumbolisu/Sandbox | NUM = 33.343 | P = 0 | POSTFIX = &&&}} |- | {{User:Tumbolisu/Sandbox | NUM = 19 | POSTFIX = % | FORMAT = BI}} |- | {{User:Tumbolisu/Sandbox | NUM = 19 | POSTFIX = % | FORMAT = BI | TOOLTIP=tooltip}} |}
Would generate:
Numbers | ||
---|---|---|
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
|