Difference between revisions of "Template:Val/delimitnum"

From blackwiki
Jump to navigation Jump to search
blackwiki>Jimp
(use Module:Gapnum)
m (42 revisions imported)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<includeonly>{{#switch:{{{fmt}}}
+
<includeonly><!--
   |commas4={{#ifexpr:abs{{{1|0}}}<1E4
+
-->{{#ifeq: <!-- compare "04" to 4, and if so, output 4-digits pure
    |{{#invoke:String|replace|{{{1|0}}}|-|−}}
+
  What might be "04" is composed of three outputs: dot, len, and fmt -->
     |{{formatnum:{{#invoke:String|replace|{{{1|0}}}|-|}}}}
+
  {{#invoke:String|find|{{{1}}}|.}}<!-- Output the zero if no dot.
   }}
+
   -->{{#invoke:String|len <!-- Length of 4 with sign and spaces filtered? -->
   |commas={{#ifexpr:{{{1|0}}}<1E4
+
    |{{#invoke:String|replace|{{{1}}}|[-+ ]|plain=false}}}}<!--
    |{{#switch:{{{u}}}
+
    That replace just filtered out any and all spaces, + or - characters.
         |BC|AD|BCE|CE={{#expr:{{{1}}}}}
+
    But it's gotta have the minus sign first in the [-charclass].
        |{{formatnum:{{#invoke:String|replace|{{{1|0}}}|-|}}}}
+
    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-->
 +
{{#invoke:String|sub|{{{1|0}}}|1|1}}
 +
  <!-- If the first char is ... -->
 +
 
 +
  |- <!-- ... one kind of dash, or another -->
 +
  |− = {{#ifeq:{{{nosign|off}}}|off|−}}<!-- output a &minus; sign unless nosign
 +
    -->{{#ifeq:
 +
          {{#invoke:String|sub|{{{1|0}}}|2|2}}|.|0}}<!--And then
 +
          then if next char is . then output a zero, else do || nothing.
 +
     -->{{#switch: {{{fmt}}} <!-- Format the rest of the number. -->
 +
      |commas={{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
 +
      |#default = {{#invoke:Gapnum|main|{{#invoke:String|sub|{{{1|0}}}|2}}}}
 +
   }}  
 +
 
 +
  <!-- follow same logic for leading + char -->
 +
   |+={{#ifeq:{{{nosign|off}}}|off|+}}<!--
 +
    -->{{#ifeq:{{#invoke:String|sub|{{{1|0}}}|2|2}}|.|0}}<!--
 +
      -->{{#switch:{{{fmt}}}
 +
         |commas = {{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
 +
        |#default = {{#invoke:Gapnum|main|{{#invoke:String|sub|{{{1|0}}}|2}}}}
 +
    }} <!-- follow similar logic for leading . char -->
 +
  |.=0<!--
 +
    -->{{#switch:{{{fmt}}}
 +
      |commas={{{1|0}}}
 +
      |#default = {{#invoke:Gapnum|main|{{{1|0}}}}}
 +
    }}
 +
 
 +
  <!-- Else if first char is not . or - or + -->
 +
  |#default = {{#switch:{{{fmt}}}
 +
    |commas={{formatnum:{{{1|0}}}}}
 +
    |#default = {{#invoke:Gapnum|main|{{{1|0}}}}}
 
       }}
 
       }}
    |{{formatnum:{{{1|0}}}}}
 
  }}
 
  |{{#ifexpr:{{{1|0}}}<1E4
 
    |{{#switch:{{{u}}}
 
        |BC|AD|BCE|CE={{#expr:{{{1}}}}}
 
        |{{#ifexpr:{{{1|0}}}<0
 
          |−{{#invoke:Gapnum|main|{{#invoke:String|replace|{{{1|0}}}|-}}}}
 
          |{{#invoke:Gapnum|main|{{{1|0}}}}}
 
        }}
 
      }}
 
    |{{#invoke:Gapnum|main|{{{1|0}}}}}
 
 
   }}
 
   }}
 
}}</includeonly><noinclude>{{documentation}}</noinclude>
 
}}</includeonly><noinclude>{{documentation}}</noinclude>

Latest revision as of 09:37, 30 September 2020

Template documentation[create]