Template:Roundup: Difference between revisions

Template page
No edit summary
mNo edit summary
Line 1: Line 1:
<includeonly>{{zero|{{#expr:{{#ifexpr: {{abs|{{{1}}}}}-({{abs|{{{1}}}}} round {{{2|0}}})<=0|({{{1}}}) round {{{2|0}}}|(({{{1}}}) round {{{2|0}}}) + ({{{1}}})/{{abs|{{{1}}}}}/{{pow|10|{{{2|0}}}}}}}}}}}</includeonly><noinclude>
<includeonly>{{zero|{{expr:{{ifexpr: {{abs|{{{1}}}}}-({{abs|{{{1}}}}} round {{{2|0}}})<=0|({{{1}}}) round {{{2|0}}}|(({{{1}}}) round {{{2|0}}}) + ({{{1}}})/{{abs|{{{1}}}}}/{{pow|10|{{{2|0}}}}}}}}}}}</includeonly><noinclude>


This template rounds up a numeric value to a limited number of decimal places.
This template rounds up a numeric value to a limited number of decimal places.

Revision as of 23:51, 10 July 2006


This template rounds up a numeric value to a limited number of decimal places.

Usage:
  • {{Roundup|value}}
  • {{Roundup|value|decimals}}
  • Both parameters can be any valid numeric expression.
  • The decimals parameter defaults to 0 and is rounded to the nearest integer.
  • decimals can be negative to round up to a multiple of a power of ten.
  • If decimals is not between -20 and 20, the value is returned without rounding.
Examples:
  • {{Roundup|3.14159|3}} = {{expr:{{ifexpr: 3.14159-(3.14159 round 3)<=0|(3.14159) round 3|((3.14159) round 3) + (3.14159)/3.14159/1000}}}}
  • {{Roundup|0|3}} = {{expr:{{ifexpr: 0-(0 round 3)<=0|(0) round 3|((0) round 3) + (0)/0/1000}}}} (should be 0, not 0.001)
  • {{Roundup|-0.00031|3}} = {{expr:{{ifexpr: 0.00031-(0.00031 round 3)<=0|(-0.00031) round 3|((-0.00031) round 3) + (-0.00031)/0.00031/1000}}}} (should be -0.001, not 0)
  • {{Roundup|-3.14159|3}} = {{expr:{{ifexpr: 3.14159-(3.14159 round 3)<=0|(-3.14159) round 3|((-3.14159) round 3) + (-3.14159)/3.14159/1000}}}}
  • {{Roundup|0|0}} = {{expr:{{ifexpr: 0-(0 round 0)<=0|(0) round 0|((0) round 0) + (0)/0/1}}}} (should be 0, not 1)
  • {{Roundup|-0.9|0}} = {{expr:{{ifexpr: 0.9-(0.9 round 0)<=0|(-0.9) round 0|((-0.9) round 0) + (-0.9)/0.9/1}}}} (should be -1, not 0)
  • {{Roundup|314159|-3}} = {{expr:{{ifexpr: 314159-(314159 round -3)<=0|(314159) round -3|((314159) round -3) + (314159)/314159/0.001}}}}
  • {{Roundup|0|-3}} = {{expr:{{ifexpr: 0-(0 round -3)<=0|(0) round -3|((0) round -3) + (0)/0/0.001}}}} (should be 0, not 1000)
  • {{Roundup|-514.15|-3}} = {{expr:{{ifexpr: 514.15-(514.15 round -3)<=0|(-514.15) round -3|((-514.15) round -3) + (-514.15)/514.15/0.001}}}} (should be -1000, not 0)
  • {{Roundup|-514159|-3}} = {{expr:{{ifexpr: 514159-(514159 round -3)<=0|(-514159) round -3|((-514159) round -3) + (-514159)/514159/0.001}}}}
Note:
  • {{Ceil|value}} is equivalent to {{Roundup|value}}.
See also: