Template:Val/delimitnum: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Jimp
allow comma formatting per MOSNUM
Ookami (talk | contribs)
m 42 revisions imported
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<includeonly><!--
<includeonly><!--
-->{{#ifeq:{{{fmt|gaps}}}|gaps
-->{{#ifeq: <!-- compare "04" to 4, and if so, output 4-digits pure
     |{{#ifexpr:({{{1|0}}}1)=({{{1|0}}})|<!--  
  What might be "04" is composed of three outputs: dot, len, and fmt -->
                Test loss of precision by appending a fixed digit "1"
  {{#invoke:String|find|{{{1}}}|.}}<!-- Output the zero if no dot.
    -->{{FormattingError|Too Many Digits|nocategory={{{nocategory|}}}}}<!--
  -->{{#invoke:String|len <!-- Length of 4 with sign and spaces filtered? -->
  -->|<!--       No loss of precision, can display this number
     |{{#invoke:String|replace|{{{1}}}|[-+ ]|plain=false}}}}<!--  
    -->{{#ifexpr:{{{1|0}}}<0|&minus;}}<!--  
    That replace just filtered out any and all spaces, + or - characters.
                Output the mathematical minus sign (not the minus-hyphen) if negative
    But it's gotta have the minus sign first in the [-charclass].
    -->{{#ifexpr:abs({{{1|0}}}1)>10*abs({{{1|0}}})|<!--  
    Any fmt given?  If so comparison to "4" will fail -->{{{fmt|}}}
                Number is an integer (no dot):
| 4 |{{#invoke:String|replace|{{{1}}}|-|&minus;}}<!--  
                appending a non-zero digit multiplies it by more than 10
If fmt is nil, found . is 0, and filtered len is 4, then 04=4,
      -->{{val/delimitnum/whole|{{#expr:abs({{{1|0}}})}}}}<!--  
and we have just output the number, replacing any - with a minus sign
                Format the integer part using (a) thin space(s) for grouping digits
 
    -->|<!--     Number is not an integer (at least contains a dot)
Else:
      -->{{val/delimitnum/whole|{{#expr:trunc(abs({{{1|0}}}))}}}}.<!--  
-->|{{#switch: <!-- its not a pure 4-digit number with no fmt options given-->
                Format the integer part using (a) thin space(s) for grouping digits,
{{#invoke:String|sub|{{{1|0}}}|1|1}}
                followed by the locale's separator before fractional decimals
  <!-- If the first char is ... -->
                (a decimal point on en-WP)
 
      -->{{val/delimitnum/fraction<!--
  |- <!-- ... one kind of dash, or another -->
        -->|{{#expr:abs({{{1|0}}}1)-trunc(abs({{{1|0}}}1))}}<!--  
  |− = {{#ifeq:{{{nosign|off}}}|off|−}}<!-- output a &minus; sign unless nosign
                The fractional part (appended with an extra digit 1
    -->{{#ifeq:
                to avoid roundoff error on last displayed digit)
          {{#invoke:String|sub|{{{1|0}}}|2|2}}|.|0}}<!--And then
        -->|{{#expr:(-ln(abs({{{1|0}}}1)-abs({{{1|0}}}))/ln10round 0)-1}}<!--  
          then if next char is . then output a zero, else do || nothing.
                The number of decimals to display (the difference of absolute values is
    -->{{#switch: {{{fmt}}} <!-- Format the rest of the number. -->
                the value of the appended digit 1, its log10 gives its position)
      |commas={{formatnum:{{#invoke:String|sub|{{{1|0}}}|2}}}}
        -->|nocategory={{{nocategory|}}}<!--
      |#default = {{#invoke:Gapnum|main|{{#invoke:String|sub|{{{1|0}}}|2}}}}
                category if formatting error (too many digits)
  }}
       -->}}<!--
 
     -->}}<!--
  <!-- follow same logic for leading + char -->
  -->}}
  |+={{#ifeq:{{{nosign|off}}}|off|+}}<!--
    |{{formatnum:{{{1}}}}}
    -->{{#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}}}}}
      }}
  }}
}}</includeonly><noinclude>{{documentation}}</noinclude>
}}</includeonly><noinclude>{{documentation}}</noinclude>

Latest revision as of 13:41, 3 September 2020