HUGO
Menu
GitHub 90265 stars Mastodon

math.Mod

Returns the modulus of two integers.
Syntax
math.Mod VALUE1 VALUE2
Returns
int64
Alias
mod

Usage

The math.Mod function returns the modulus of two integers, which is the remainder after dividing VALUE1 by VALUE2. The result has the same sign as VALUE1. The function converts both values to integers before dividing, removing any fractional part, and throws an error if VALUE2 is 0.

Examples

{{ math.Mod 15 3 }} → 0
{{ math.Mod 15 4 }} → 3

With a negative number:

{{ math.Mod -15 4 }} → -3