Template:Roundup: Difference between revisions

Template page
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
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.
; Usage
 
* {{tlp|{{PAGENAME}}|''value''}}
; Usage<nowiki>:</nowiki>
* {{tlp|{{PAGENAME}}|''value''|''decimals''}}
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|</nowiki></tt>''value''<tt><nowiki>}}</nowiki></tt>
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|</nowiki></tt>''value''<tt><nowiki>|</nowiki></tt>''decimals''<tt><nowiki>}}</nowiki></tt>
* Both parameters can be any valid numeric expression.
* Both parameters can be any valid numeric expression.
* The ''decimals'' parameter defaults to 0 and is rounded to the nearest integer.
* 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.
* ''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.
* If ''decimals'' is not between -20 and 20, the ''value'' is returned without rounding.
; Examples<nowiki>:</nowiki>
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|3.14159|3}}</nowiki></tt> = {{{{PAGENAME}}|3.14159|3}}
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|0|3}}</nowiki></tt> = {{{{PAGENAME}}|0|3}} (should be 0, not 0.001)
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|-0.00031|3}}</nowiki></tt> = {{{{PAGENAME}}|-0.00031|3}} (should be -0.001, not 0)
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|-3.14159|3}}</nowiki></tt> = {{{{PAGENAME}}|-3.14159|3}}
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|0|0}}</nowiki></tt> = {{{{PAGENAME}}|0|0}} (should be 0, not 1)
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|-0.9|0}}</nowiki></tt> = {{{{PAGENAME}}|-0.9|0}} (should be -1, not 0)
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|314159|-3}}</nowiki></tt> = {{{{PAGENAME}}|314159|-3}}
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|0|-3}}</nowiki></tt> = {{{{PAGENAME}}|0|-3}} (should be 0, not 1000)
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|-514.15|-3}}</nowiki></tt> = {{{{PAGENAME}}|-514.15|-3}} (should be -1000, not 0)
* <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|-514159|-3}}</nowiki></tt> = {{{{PAGENAME}}|-514159|-3}}
; Note<nowiki>:</nowiki>
* <tt><nowiki>{{</nowiki>Ceil<nowiki>|</nowiki></tt>''value''<tt><nowiki>}}</nowiki></tt> is equivalent to <tt><nowiki>{{</nowiki>{{PAGENAME}}<nowiki>|</nowiki></tt>''value''<tt><nowiki>}}</nowiki></tt>.
; See also<nowiki>:</nowiki>
* [[Template:Rounddown]]


[[Category:Mathematical templates|{{PAGENAME}}]]
[[Category:Mathematical templates|{{PAGENAME}}]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
</noinclude>
</noinclude>

Latest revision as of 16:00, 2 August 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.