Difference between revisions of "Template:Val/delimitnum"

From blackwiki
Jump to navigation Jump to search
blackwiki>Cpiral
(4-digit pure, and no fmt=commas4, and no concern with units)
m (42 revisions imported)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
<includeonly>{{#ifeq:  
+
<includeonly><!--
{{#invoke:String|find|{{{1}}}|[+-.]|plain=false}}{{#invoke:String|len|{{{1}}}}}{{{fmt|}}}
+
-->{{#ifeq: <!-- compare "04" to 4, and if so, output 4-digits pure
| 4 |{{{1}}}<!-- if fmt is nil,found +=. is 0, len is 4,  
+
  What might be "04" is composed of three outputs: dot, len, and fmt -->
then 04=4, output the number, else:  
+
  {{#invoke:String|find|{{{1}}}|.}}<!-- Output the zero if no dot.
 +
  -->{{#invoke:String|len <!-- Length of 4 with sign and spaces filtered? -->
 +
    |{{#invoke:String|replace|{{{1}}}|[-+ ]|plain=false}}}}<!--
 +
    That replace just filtered out any and all spaces, + or - characters.
 +
    But it's gotta have the minus sign first in the [-charclass].
 +
    Any fmt given?  If so comparison to "4" will fail -->{{{fmt|}}}
 +
| 4 |{{#invoke:String|replace|{{{1}}}|-|&minus;}}<!--  
 +
If fmt is nil, found . is 0, and filtered len is 4, then 04=4,  
 +
and we have just output the number, replacing any - with a minus sign
 +
 
 +
Else:  
 
-->|{{#switch: <!-- its not a pure 4-digit number with no fmt options given-->
 
-->|{{#switch: <!-- its not a pure 4-digit number with no fmt options given-->
 
{{#invoke:String|sub|{{{1|0}}}|1|1}}
 
{{#invoke:String|sub|{{{1|0}}}|1|1}}

Latest revision as of 09:37, 30 September 2020

Template documentation[create]