trunc
Drops the decimals of a number, rounding toward zero.
Keyboard Maestro: TRUNC
Details #
trunc(number) takes exactly one argument and returns the whole number nearest to zero: it cuts off the decimals. trunc(2.9) is 2 and trunc(-2.9) is -2.
floor differs for negatives (floor(-2.9) is -3), and round goes to the nearest whole number.
Parameters #
Takes 1 argument.
{{ trunc(text) }}
Examples #
trunc(2.9)→
2trunc(-2.9)→
-2trunc(price * 100) / 100→
4.98| Sample variable | Value |
|---|---|
price | 4.987 |
Gotchas #
Calling it with no argument or two arguments is an error:
trunc() takes 1 argument, got 2.Anything that isn't a number is an error:
trunc() needs a number, got text. Numeric text such as "0.5" is accepted.