Filters for Mathematical Operations with Scriptlets
Scriptlets allow you to easily perform mathematical operations on a string. You may add, subtract, multiply, or divide two numbers, or perform any mathematical operation on a number.
round
Rounds a number to the specific decimal places. If no decimal places are specified, the number is rounded to the nearest whole number.
{? "18.95" | round ?}
// Output: 19
{? "18.9594" | round: 2 ?}
// Output 18.96 (rounds up to 2 decimal places)
times
Multiplies a number by another number
{? "18.9594" | times: 2 | round: 2 ?}
// Output: 37.92
abs
Returns the absolute value of a number
{? "-12.34" | abs ?}
ceil
Rounds the input up to the nearest whole number
{? "12.34" | ceil ?}
// Output: 13
floor
Rounds the input down to the nearest whole number
{? "16.94" | floor ?}
// Output: 16
plus
Adds a number to another number
{? "18" | plus: 2 ?}
// Output: 20
minus
Subtracts a number from another number
{? "18" | minus: 2 ?}
// Output: 16
divided_by
Divides a number by another number
{? "16.04" | divided_by: 4 ?}
// Output: 4.01
{? 20 | divided_by: 7 | round: 2 ?}
// Output: 2.86
modulo
Returns the remainder of a division operation
{? "19" | modulo: 2 ?}
// Output: 1
at_least
Limits a number to a minimum value
{? "12.34" | at_least: 10 ?}
// Output: 12.34
{? "4" | at_least: 5 ?}
// Output: 5
at_most
Limits a number to a maximum value
{? "12.34" | at_most: 5 ?}
// Output: 5