Template:Trunc
From Meta, a Wikimedia project coordination wiki
template:Trunc (edit•talk•links•history) truncates a given number or the result of a given numerical expression to a whole number by removing any fraction (digits after the decimal point).
- Examples:
- {{
Trunc|3.2}} = 3, {{Trunc|-3.2}} = -3 - {{
Trunc|1.6}} = 1, {{Trunc|-1.6}} = -1 - {{
Trunc|0.8}} = 0, {{Trunc|-0.8}} = 0 - {{
Trunc|0.4}} = 0, {{Trunc|-0.4}} = 0 - {{
Trunc|9-9}} = 0, {{Trunc|-0.0}} = 0 - It can be better to evaluate expressions once outside of Trunc:
- {{Trunc|{{#expr: 4.5 / 3 }}}} = 1
- Trunc supports optional substitution with subst=subst:
- {{ subst:Trunc|numerical expression|subst=subst: }}
- To copy the code into another template use only subst:
- {{ subst:Trunc|{{{x|1}}} }} inserts code for {{{x|1}}}
- template:Roundtozero (edit•talk•links•history) offers more features, it's also more complex.