Template:Val/delimitnum: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Jimp
handling of ".1" etc.
meta>Cpiral
4-digit pure, and no fmt=commas4, and no concern with units
Line 1: Line 1:
<includeonly>{{#switch:{{#invoke:String|sub|{{{1|0}}}|1|1}}
<includeonly>{{#ifeq:  
  |-|−={{#ifeq:{{{nosign|off}}}|off
{{#invoke:String|find|{{{1}}}|[+-.]|plain=false}}{{#invoke:String|len|{{{1}}}}}{{{fmt|}}}
    |−
| 4 |{{{1}}}<!-- if fmt is nil,found +=. is 0, len is 4,
  }}{{#ifeq:{{#invoke:String|sub|{{{1|0}}}|2|2}}|.
then 04=4, output the number, else:
    |0
-->|{{#switch: <!-- its not a pure 4-digit number with no fmt options given-->
  }}{{#switch:{{{fmt}}}
{{#invoke:String|sub|{{{1|0}}}|1|1}}
    |commas4={{#ifexpr:{{#invoke:String|sub|{{{1|0}}}|2}}<1E4
  <!-- If the first char is ... -->
        |{{#invoke:String|sub|{{{1|0}}}|2}}
 
        |{{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
  |- <!-- ... one kind of dash, or another -->
      }}
  |− = {{#ifeq:{{{nosign|off}}}|off|−}}<!-- output a &minus; sign unless nosign
    |commas={{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
    -->{{#ifeq:
    |{{#invoke:Gapnum|main|{{#invoke:String|sub|{{{1|0}}}|2}}}}
          {{#invoke:String|sub|{{{1|0}}}|2|2}}|.|0}}<!--And then
   }}
          then if next char is . then output a zero, else do || nothing.
   |+={{#ifeq:{{{nosign|off}}}|off
    -->{{#switch: {{{fmt}}} <!-- Format the rest of the number. -->
    |+
      |commas={{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
  }}{{#ifeq:{{#invoke:String|sub|{{{1|0}}}|2|2}}|.
      |#default = {{#invoke:Gapnum|main|{{#invoke:String|sub|{{{1|0}}}|2}}}}
    |0
   }}  
  }}{{#switch:{{{fmt}}}
 
    |commas4={{#ifexpr:{{{1|0}}}<1E4
  <!-- follow same logic for leading + char -->
        |{{#invoke:String|sub|{{{1|0}}}|2}}
   |+={{#ifeq:{{{nosign|off}}}|off|+}}<!--
         |{{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
    -->{{#ifeq:{{#invoke:String|sub|{{{1|0}}}|2|2}}|.|0}}<!--
      }}
      -->{{#switch:{{{fmt}}}
    |commas={{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
         |commas = {{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
    |{{#invoke:Gapnum|main|{{#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}}}
   |.=0<!--
    |commas4
    -->{{#switch:{{{fmt}}}
    |commas={{{1|0}}}
      |commas={{{1|0}}}
    |{{#invoke:Gapnum|main|{{{1|0}}}}}
      |#default = {{#invoke:Gapnum|main|{{{1|0}}}}}
  }}
    }}
   |{{#switch:{{{fmt}}}
 
    |commas4={{#ifexpr:abs{{{1|0}}}<1E4
  <!-- Else if first char is not . or - or + -->
        |{{{1|0}}}
   |#default = {{#switch:{{{fmt}}}  
        |{{formatnum:{{{1|0}}}}}
     |commas={{formatnum:{{{1|0}}}}}
      }}
     |#default = {{#invoke:Gapnum|main|{{{1|0}}}}}
     |commas={{#ifexpr:{{{1|0}}}<1E4
        |{{#switch:{{{u}}}
          |BC|AD|BCE|CE={{{1|0}}}
          |{{formatnum:{{{1|0}}}}}
        }}
        |{{formatnum:{{{1|0}}}}}
      }}
     |{{#ifexpr:{{{1|0}}}<1E4
        |{{#switch:{{{u}}}
          |BC|AD|BCE|CE={{{1|0}}}
          |{{#invoke:Gapnum|main|{{{1|0}}}}}
        }}
        |{{#invoke:Gapnum|main|{{{1|0}}}}}
       }}
       }}
   }}
   }}
}}</includeonly><noinclude>{{documentation}}</noinclude>
}}</includeonly><noinclude>{{documentation}}</noinclude>

Revision as of 21:55, 18 June 2015