Template:Val/delimitnum: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Jimp
m commentary
meta>Jimp
allow for overriding formatting if u is AD, BC, etc. also allow formatting with commas for ±10^4 & over/under
Line 1: Line 1:
<includeonly><!--  
<includeonly><!--
                 Test loss of precision by appending a fixed digit "1"
                 Test loss of precision by appending a fixed digit "1"
-->{{#ifexpr:({{{1|0}}}1)=({{{1|0}}})<!--
-->{{#ifexpr:({{{1|0}}}1)=({{{1|0}}})<!--
Line 7: Line 7:


   -->|<!--      Precision is not lost. Display the number.
   -->|<!--      Precision is not lost. Display the number.
  -->{{val/delimitnum/{{{fmt|gaps}}}<!--
                Output the mathematical minus sign (not the minus-hyphen) if negative
                    -->{{#expr:{{{1|0}}}<0}}<!--
  -->{{#ifexpr:{{{1|0}}}<0|&minus;}}<!--
                    -->{{#expr:trunc({{{1|0}}}9)={{{1|0}}}9}}|{{{1|0}}}<!--
    -->|u={{{u}}}<!--
  -->}}<!--


                Format according to the parameter fmt.
  -->{{#ifeq:{{{fmt|gaps}}}|gaps<!--
                Test whether the number is an integer.
    -->|{{#ifexpr:trunc({{{1|0}}}9)={{{1|0}}}9
          |<!--
                The number is an integer.
                Format it using (a) thin space(s) for grouping digits.
                Do not add a decimal point.
      -->{{val/delimitnum/whole|{{#expr:abs({{{1|0}}})}}}}<!---
        -->|<!--
                The number is not an integer.
                Split the number into an integer part an a fractional part.
                Format the integer part using (a) thin space(s) for grouping digits.
                Add a decimal point.
        -->{{val/delimitnum/whole|{{#expr:trunc(abs({{{1|0}}}))}}}}.<!-- 
                Format the fractional part using (a) thin space(s) for grouping digits.
        -->{{val/delimitnum/fraction<!--
          -->|{{#expr:abs({{{1|0}}}1)-trunc(abs({{{1|0}}}1))}}<!--
                The fractional part (appended with an extra digit 1
                to avoid roundoff error on last displayed digit)
          -->|{{#expr:(-ln(abs({{{1|0}}}1)-abs({{{1|0}}}))/ln10round 0)-1}}<!--
                The number of decimals to display (the difference of absolute values is
                the value of the appended digit 1, its log10 gives its position)
          -->|nocategory={{{nocategory|}}}<!--
                category if formatting error (too many digits)
        -->}}<!--
    -->}}<!--
                Format using commas to the left.
                Test whether the number is an integer.
    -->|{{#ifexpr:trunc({{{1|0}}}9)={{{1|0}}}9
          |<!--
                The number is an integer.
                Format with commas.
        -->{{formatnum:{{#expr:abs{{{1}}}}}}}
          |<!--
                The number is not an integer.
                Format the whole part with commas.
        -->{{formatnum:{{#expr:trunc(abs{{{1}}})}}}}<!--
                Add the fractional part including trailing zeros.
        -->{{padright:<!--
                Remove the leading zero from the truncated number.
            -->{{#Invoke:String<!--
              -->|sub<!--
              -->|{{#expr:abs({{{1|0}}})-trunc(abs({{{1|0}}}))}}<!--
              -->|2<!--
            -->}}<!--  END invoke string
          -->|<!--
                Calculate the total number of characters to display
                (including the decimal point
            -->{{#expr:(-ln(abs({{{1|0}}}1)-abs({{{1|0}}}))/ln10round 0)}}<!--
        -->}}<!-- END padright
      -->}}<!-- END integer test
  -->}}<!-- END formatting commas vs gaps
-->}}</includeonly><noinclude>{{documentation}}</noinclude>
-->}}</includeonly><noinclude>{{documentation}}</noinclude>

Revision as of 10:24, 27 February 2014