math functionsMath functions available through the object 'math' in scriban.
math.absmath.ceilmath.divided_bymath.floormath.formatmath.is_numbermath.minusmath.modulomath.plusmath.roundmath.timesmath.uuidmath.randommath.absmath.abs <value>
Returns the absolute value of a specified number.
value: The input valueThe absolute value of the input value
input Try out
{{ -15.5| math.abs }}
{{ -5| math.abs }}
output
15.5
5
math.ceilmath.ceil <value>
Returns the smallest integer greater than or equal to the specified number.
value: The input valueThe smallest integer greater than or equal to the specified number.
input Try out
{{ 4.6 | math.ceil }}
{{ 4.3 | math.ceil }}
output
5
5
math.divided_bymath.divided_by <value> <divisor>
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.
value: The input valuedivisor: The divisor valueThe division of value by divisor.
input Try out
{{ 8.4 | math.divided_by 2.0 | math.round 1 }}
{{ 8.4 | math.divided_by 2 }}
output
4.2
4
math.floormath.floor <value>
Returns the largest integer less than or equal to the specified number.
value: The input valueThe largest integer less than or equal to the specified number.
input Try out
{{ 4.6 | math.floor }}
{{ 4.3 | math.floor }}
output
4
4
math.formatmath.format <value> <format> <culture>?
Formats a number value with specified .NET standard numeric format strings
value: The input valueformat: The format string.culture: The culture as a string (e.g en-US). By default the culture from is usedThe largest integer less than or equal to the specified number.
input Try out
{{ 255 | math.format "X4" }}
output
00FF
math.is_numbermath.is_number <value>
Returns a boolean indicating if the input value is a number
value: The input valuetrue if the input value is a number; otherwise false.
input Try out
{{ 255 | math.is_number }}
{{ "yo" | math.is_number }}
output
true
false
math.minusmath.minus <value> <with>
Subtracts from the input value the with value
value: The input valuewith: The with value to subtract from valueThe results of the subtraction: value - with
input Try out
{{ 255 | math.minus 5}}
output
250
math.modulomath.modulo <value> <with>
Performs the modulo of the input value with the with value
value: The input valuewith: The with value to module valueThe results of the modulo: value % with
input Try out
{{ 11 | math.modulo 10}}
output
1
math.plusmath.plus <value> <with>
Performs the addition of the input value with the with value
value: The input valuewith: The with value to add tovalueThe results of the addition: value + with
input Try out
{{ 1 | math.plus 2}}
output
3
math.roundmath.round <value> <precision: 0>?
Rounds a value to the nearest integer or to the specified number of fractional digits.
value: The input valueprecision: The number of fractional digits in the return value. Default is 0.A value rounded to the nearest integer or to the specified number of fractional digits.
input Try out
{{ 4.6 | math.round }}
{{ 4.3 | math.round }}
{{ 4.5612 | math.round 2 }}
output
5
4
4.56
math.timesmath.times <value> <with>
Performs the multiplication of the input value with the with value
value: The input valuewith: The with value to multiply tovalueThe results of the multiplication: value * with
input Try out
{{ 2 | math.times 3}}
output
6
math.uuidmath.uuid
Creates a new UUID
The created UUID, ex. 2dc55d50-3f6c-446a-87d0-a5a4eed23269
input Try out
{{ math.uuid }}
output
1c0a4aa8-680e-4bd6-95e9-cdbec45ef057
math.randommath.random <minValue> <maxValue>
Creates a random number
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.A random number greater or equal to minValue and less than maxValue
input Try out
{{ math.random 1 10 }}
output
7
Note: This document was automatically generated from the source code using
Scriban.DocGen.