Template:Val/delimitnum: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Jimp
delimiting using gaps either side of the decimal point per MOSNUM, see Template_talk:Val#Delimiting
meta>Jimp
allow comma formatting per MOSNUM
Line 1: Line 1:
<includeonly><!--
<includeonly><!--
-->{{#ifexpr:({{{1|0}}}1)=({{{1|0}}})|<!-- Test loss of precision by appending a fixed digit "1"
-->{{#ifeq:{{{fmt|gaps}}}|gaps
  -->{{FormattingError|Too Many Digits|nocategory={{{nocategory|}}}}}<!--
    |{{#ifexpr:({{{1|0}}}1)=({{{1|0}}})|<!--  
-->|<!-- No loss of precision, can display this number
                Test loss of precision by appending a fixed digit "1"
  -->{{#ifexpr:{{{1|0}}}<0|&minus;}}<!-- Output the mathematical minus sign (not the minus-hyphen) if negative
    -->{{FormattingError|Too Many Digits|nocategory={{{nocategory|}}}}}<!--
  -->{{#ifexpr:abs({{{1|0}}}1)>10*abs({{{1|0}}})|<!-- Number is an integer (no dot): appending a non-zero digit multiplies it by more than 10
  -->|<!--       No loss of precision, can display this number
    -->{{val/delimitnum/whole|{{#expr:abs({{{1|0}}})}}}}<!-- Format the integer part using (a) thin space(s) for grouping digits
    -->{{#ifexpr:{{{1|0}}}<0|&minus;}}<!--  
  -->|<!-- Number is not an integer (at least contains a dot)
                Output the mathematical minus sign (not the minus-hyphen) if negative
    -->{{val/delimitnum/whole|{{#expr:trunc(abs({{{1|0}}}))}}}}.<!-- Format the integer part using (a) thin space(s) for grouping digits, followed by the locale's separator before fractional decimals (a decimal point on en-WP)
    -->{{#ifexpr:abs({{{1|0}}}1)>10*abs({{{1|0}}})|<!--  
    -->{{val/delimitnum/fraction<!--
                Number is an integer (no dot):  
      -->|{{#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)
                appending a non-zero digit multiplies it by more than 10
      -->|{{#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)
      -->{{val/delimitnum/whole|{{#expr:abs({{{1|0}}})}}}}<!--  
      -->|nocategory={{{nocategory|}}}<!-- category if formatting error (too many digits)
                Format the integer part using (a) thin space(s) for grouping digits
    -->|<!--     Number is not an integer (at least contains a dot)
      -->{{val/delimitnum/whole|{{#expr:trunc(abs({{{1|0}}}))}}}}.<!--  
                Format the integer part using (a) thin space(s) for grouping digits,  
                followed by the locale's separator before fractional decimals  
                (a decimal point on en-WP)
      -->{{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)
      -->}}<!--
     -->}}<!--
     -->}}<!--
   -->}}<!--
   -->}}
-->}}</includeonly><noinclude>{{documentation}}</noinclude>
    |{{formatnum:{{{1}}}}}
}}</includeonly><noinclude>{{documentation}}</noinclude>

Revision as of 10:19, 15 January 2014