Numeric

The Numeric registry includes a range of utilities for performing numerical operations and calculations, making it easier to handle numbers and perform math functions in your templates.

You can easily import all the functions from the numeric registry by including the following import statement in your code

import "github.com/go-sprout/sprout/registry/numeric"

floor

The function returns the largest integer that is less than or equal to the provided number.

Signature

Must version

❌

{{ 3.7 | floor }} // Output: 3
{{ floor 1.5 }} // Output: 1
{{ floor 123.9999 }} // Output: 123
{{ floor 123.0001 }} // Output: 123

ceil

The function returns the smallest integer that is greater than or equal to the provided number.

Signature

Must version

❌

{{ 3.1 | ceil }} // Output: 4
{{ ceil 1.5 }} // Output: 2
{{ ceil 123.9999 }} // Output: 124
{{ ceil 123.0001 }} // Output: 124

round

The function rounds a number to a specified precision, allowing control over the number of decimal places. It also considers an optional rounding threshold to determine whether to round up or down (default to 0.5).

Signature

Must version

❌

add / addf

The function performs addition on a slice of values, summing all elements in the slice and returning the total.

Signature

Must version

❌

add1 / add1f

The function performs a unary addition, incrementing the provided value by one.

Signature

Must version

❌

sub / subf

The function performs subtraction on a slice of values, starting with the first value and subtracting each subsequent value from it.

Signature

Must version

❌

mul

The function multiplies a sequence of values together and returns the result as an int64.

Signature

Must version

❌

mulf

The function multiplies a sequence of values and returns the result as a float64.

Signature

Must version

❌

div

The function divides a sequence of values and returns the result as an int64.

Signature

Must version

❌

divf

The function divides a sequence of values, starting with the first value, and returns the result as a float64.

Signature

Must version

❌

mod

The function returns the remainder of the division of x by y.

Signature

Must version

❌

min

The function returns the minimum value among the provided arguments.

Signature

Must version

❌

minf

The function returns the minimum value among the provided floating-point arguments.

Signature

Must version

❌

max

The function returns the maximum value among the provided arguments.

Signature

Must version

❌

maxf

The function returns the maximum value among the provided floating-point arguments.

Signature

Must version

❌

tt

Last updated