Template:Val/delimitnum: Difference between revisions

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

Latest revision as of 13:41, 3 September 2020