Jump to content

Template:Trunc

From mediawiki.org
Template documentation


This template produces an expression for the truncated value of a given expression. If the value is in the range of integer-type numbers (in the range −9,223,372,036,854,776,000 through 9,223,372,036,854,776,000), the resulting expression is of type integer.

The template also serves as a tool to enter an integer larger than 9,007,199,254,740,992, avoiding rounding to float: split the digits up into two parameters, each forming an integer not larger than that limit, and avoiding leading zeros in the second parameter. If the latter requires a larger first parameter: for every trailing 0 it can be a factor 2 larger then mentioned (see also Help:Calculation accuracy#Integers). To enter an integer smaller than -9,007,199,254,740,992 explicitly, do the same with a minus sign before each part.

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

See m:Template:Trunc for examples.