Math functions
Math functions available through the object math in scriban.
math.absmath.ceilmath.divided_bymath.floormath.formatmath.is_numbermath.minusmath.modulomath.plusmath.roundmath.timesmath.uuidmath.random
math.abs
math.abs <value>Description
Returns the absolute value of a specified number.
Arguments
value: The input value
Returns
The absolute value of the input value
Examples
input
{{ -15.5| math.abs }}
{{ -5| math.abs }}output
15.5 5math.ceil
math.ceil <value>Description
Returns the smallest integer greater than or equal to the specified number.
Arguments
value: The input value
Returns
The smallest integer greater than or equal to the specified number.
Examples
input
{{ 4.6 | math.ceil }}
{{ 4.3 | math.ceil }}output
5 5math.divided_by
math.divided_by <value> <divisor>Description
Divides the specified value by another value. If the divisor is an integer, the result will be floor to and converted back to an integer.
Arguments
value: The input valuedivisor: The divisor value
Returns
The division of value by divisor.
Examples
input
{{ 8.4 | math.divided_by 2.0 | math.round 1 }}
{{ 8.4 | math.divided_by 2 }}output
4.2 4math.floor
math.floor <value>Description
Returns the largest integer less than or equal to the specified number.
Arguments
value: The input value
Returns
The largest integer less than or equal to the specified number.
Examples
input
{{ 4.6 | math.floor }}
{{ 4.3 | math.floor }}output
4 4math.format
math.format <value> <format> <culture>?Description
Formats a number value with specified .NET standard numeric format strings
Arguments
value: The input valueformat: The format string.culture: The culture as a string (e.gen-US). By default the culture from is used
Returns
The largest integer less than or equal to the specified number.
Examples
input
{{ 255 | math.format "X4" }}output
00FFmath.is_number
math.is_number <value>Description
Returns a boolean indicating if the input value is a number
Arguments
value: The input value
Returns
true if the input value is a number; otherwise false.
Examples
input
{{ 255 | math.is_number }}
{{ "yo" | math.is_number }}
{{ null | math.is_number }}output
true false falsemath.minus
math.minus <value> <with>Description
Subtracts from the input value the with value
Arguments
value: The input valuewith: The with value to subtract fromvalue
Returns
The results of the subtraction: value - with
Examples
input
{{ 255 | math.minus 5}}output
250math.modulo
math.modulo <value> <with>Description
Performs the modulo of the input value with the with value
Arguments
value: The input valuewith: The with value to modulevalue
Returns
The results of the modulo: value % with
Examples
input
{{ 11 | math.modulo 10}}output
1math.plus
math.plus <value> <with>Description
Performs the addition of the input value with the with value
Arguments
value: The input valuewith: The with value to add tovalue
Returns
The results of the addition: value + with
Examples
input
{{ 1 | math.plus 2}}output
3math.round
math.round <value> <precision: 0>?Description
Rounds a value to the nearest integer or to the specified number of fractional digits.
Arguments
value: The input valueprecision: The number of fractional digits in the return value. Default is 0.
Returns
A value rounded to the nearest integer or to the specified number of fractional digits.
Examples
input
{{ 4.6 | math.round }}
{{ 4.3 | math.round }}
{{ 4.5612 | math.round 2 }}output
5 4 4.56math.times
math.times <value> <with>Description
Performs the multiplication of the input value with the with value
Arguments
value: The input valuewith: The with value to multiply tovalue
Returns
The results of the multiplication: value * with
Examples
input
{{ 2 | math.times 3}}output
6math.uuid
math.uuidDescription
Creates a new UUID
Arguments
Returns
The created UUID, ex. 2dc55d50-3f6c-446a-87d0-a5a4eed23269
Examples
input
{{ math.uuid }}output
1c0a4aa8-680e-4bd6-95e9-cdbec45ef057math.random
math.random <minValue> <maxValue>Description
Creates a random number
Arguments
minValue: The inclusive lower bound of the random number returnedmaxValue: The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue.
Returns
A random number greater or equal to minValue and less than maxValue
Examples
input
{{ math.random 1 10 }}output
7