Difference between revisions of "Template:Val/delimitnum"
Jump to navigation
Jump to search
blackwiki>Jimp (trailing zeros for fmt=commas) |
blackwiki>Jimp (bypass template {{str right}} to go directly to module & add comments) |
||
| Line 48: | Line 48: | ||
Test whether the number is an integer. | Test whether the number is an integer. | ||
-->|{{#ifexpr:trunc({{{1|0}}}9)={{{1|0}}}9 | -->|{{#ifexpr:trunc({{{1|0}}}9)={{{1|0}}}9 | ||
| − | |{{formatnum:{{#expr:abs{{{1}}}}}}} | + | |<!-- |
| − | |{{formatnum:{{#expr:trunc(abs{{{1}}})}}}}<!-- | + | The number is an integer. |
| − | -->{{padright:{{ | + | Format with commas. |
| − | -->|{{#expr:(-ln(abs({{{1|0}}}1)-abs({{{1|0}}}))/ln10round 0)}}<!-- | + | -->{{formatnum:{{#expr:abs{{{1}}}}}}} |
| − | -->}}<!-- | + | |<!-- |
| − | -->}}<!-- | + | The number is not an integer. |
| − | -->}}<!-- | + | Format the whole part with commas. |
| + | -->{{formatnum:{{#expr:trunc(abs{{{1}}})}}}}<!-- | ||
| + | |||
| + | Add trailing zeros. | ||
| + | -->{{padright:<!-- | ||
| + | |||
| + | Remove the leading zero from the truncated number. | ||
| + | -->{{#Invoke:String<!-- | ||
| + | -->|sub<!-- | ||
| + | -->|{{#expr:abs({{{1|0}}})-trunc(abs({{{1|0}}}))}}<!-- | ||
| + | -->|2<!-- | ||
| + | -->}}<!-- END invoke string | ||
| + | -->|<!-- | ||
| + | |||
| + | Calculate the total number of characters to display | ||
| + | (including the decimal point | ||
| + | -->{{#expr:(-ln(abs({{{1|0}}}1)-abs({{{1|0}}}))/ln10round 0)}}<!-- | ||
| + | |||
| + | -->}}<!-- END padright | ||
| + | -->}}<!-- END integer test | ||
| + | -->}}<!-- END formatting commas vs gaps | ||
-->}}</includeonly><noinclude>{{documentation}}</noinclude> | -->}}</includeonly><noinclude>{{documentation}}</noinclude> | ||