math functions

Math functions available through the object 'math' in scriban.

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 Try out

{{ -15.5| math.abs }}
{{ -5| math.abs }}

output

15.5
5

math.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 Try out

{{ 4.6 | math.ceil }}
{{ 4.3 | math.ceil }}

output

5
5

math.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 value
  • divisor: The divisor value

Returns

The division of value by divisor.

Examples

input Try out

{{ 8.4 | math.divided_by 2.0 | math.round 1 }}
{{ 8.4 | math.divided_by 2 }}

output

4.2
4

math.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 Try out

{{ 4.6 | math.floor }}
{{ 4.3 | math.floor }}

output

4
4

math.format

math.format <value> <format> <culture>?

Description

Formats a number value with specified .NET standard numeric format strings

Arguments

  • value: The input value
  • format: The format string.
  • culture: The culture as a string (e.g en-US). By default the culture from is used

Returns

The largest integer less than or equal to the specified number.

Examples

input Try out

{{ 255 | math.format "X4" }}

output

00FF

math.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 Try out

{{ 255 | math.is_number }}
{{ "yo" | math.is_number }}

output

true
false

math.minus

math.minus <value> <with>

Description

Subtracts from the input value the with value

Arguments

  • value: The input value
  • with: The with value to subtract from value

Returns

The results of the subtraction: value - with

Examples

input Try out

{{ 255 | math.minus 5}}

output

250

math.modulo

math.modulo <value> <with>

Description

Performs the modulo of the input value with the with value

Arguments

  • value: The input value
  • with: The with value to module value

Returns

The results of the modulo: value % with

Examples

input Try out

{{ 11 | math.modulo 10}}

output

1

math.plus

math.plus <value> <with>

Description

Performs the addition of the input value with the with value

Arguments

  • value: The input value
  • with: The with value to add tovalue

Returns

The results of the addition: value + with

Examples

input Try out

{{ 1 | math.plus 2}}

output

3

math.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 value
  • precision: 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 Try out

{{ 4.6 | math.round }}
{{ 4.3 | math.round }}
{{ 4.5612 | math.round 2 }}

output

5
4
4.56

math.times

math.times <value> <with>

Description

Performs the multiplication of the input value with the with value

Arguments

  • value: The input value
  • with: The with value to multiply tovalue

Returns

The results of the multiplication: value * with

Examples

input Try out

{{ 2 | math.times 3}}

output

6

math.uuid

math.uuid

Description

Creates a new UUID

Arguments

Returns

The created UUID, ex. 2dc55d50-3f6c-446a-87d0-a5a4eed23269

Examples

input Try out

{{ math.uuid }}

output

1c0a4aa8-680e-4bd6-95e9-cdbec45ef057

math.random

math.random <minValue> <maxValue>

Description

Creates a random number

Arguments

  • minValue: The inclusive lower bound of the random number returned
  • maxValue: 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 Try out

{{ math.random 1 10 }}

output

7

Note: This document was automatically generated from the source code using Scriban.DocGen.