Template:Round0

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search


This template produces an expression for the value of a given expression, rounded to an integer. If the value is in the range of integer-type numbers, the resulting expression is of type integer.

Thus, when applying #expr, if the value is in the range of integer-type numbers the exact result is produced. The reason for not applying #expr in this template is:

  • for integer-type numbers: in subsequent use in another expression the value would be rounded to float
  • for floats: they would be rounded to 14 digits

Examples:

  • {{round0|123.45}} → ((123.45)round0)
  • {{round0|10/7}} → ((10/7)round0)
  • {{round0|123.45e20}} → (123.45e20)

Advantages compared with the operator round with second argument 0:

  • that operator gives wrong results for odd numbers between 2^52 and 2^53, even though the exact results are representable as float
  • for integer-type numbers with an absolute value between 2^53 and 2^63 the operator rounds to float, while the template gives the integer-type expression for the exact result