---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.5
alternate:
  - https://divkit.tech/docs/en/concepts/functions.md
  - https://divkit.tech/docs/ru/concepts/functions.md
  - href: en/concepts/functions.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://divkit.tech/docs/en/llms.txt

# Embedded functions

## Type conversion {#std}

#|
||
**Function**
|
**Description**
||

||
`toBoolean(integer) boolean`
|
Converts the argument to a boolean.
Returns `true` if the argument is `1`, `false` if the argument is `0`, or an error otherwise.

<br>

Argument: `integer` value.

||

||
`toBoolean(string) boolean`
|
Converts the argument to a boolean.
Returns `true` if the argument is `"true"`, `false` if the argument is `"false"`, or an error otherwise.

<br>

Argument: `string` value.

||

||
`toInteger(boolean) integer`
|
Converts the argument to an integer.
Returns `1` if the argument is `true` and `0` if the argument is `false`.

<br>

Argument: `boolean` value.

||

||
`toInteger(number) integer`
|
Converts the argument to an integer. Rounds down the result.
Returns an `integer`.

<br>

Argument: `number` value.

||

||
`toInteger(string) integer`
|
Converts the argument to an integer.
Returns an `integer`.

<br>

Argument: `string` value.

||

||
`toNumber(integer) number`
|
Converts the argument to a floating-point number.
Returns a `number`.

<br>

Argument: `integer` value.

||

||
`toNumber(string) number`
|
Converts the argument to a floating-point number.
Returns a `number`.

<br>

Argument: `string` value.

||

||
`toString(boolean) string`
|
Converts the argument to a string.
Returns a `string`.

<br>

Argument: `boolean` value.

||

||
`toString(integer) string`
|
Converts the argument to a string.
Returns a `string`.

<br>

Argument: `integer` value.

||

||
`toString(number) string`
|
Converts the argument to a string.
Returns a `string`.

<br>

Argument: `number` value.

||

||
`encodeUri(string) string`
|
Encodes the string in `application/x-www-form-urlencoded` format.
Returns the encoded `string` value.

<br>

Argument: `string` value.

||

||
`decodeUri(string) string`
|
Decodes the `application/x-www-form-urlencoded` string.
Returns the decoded `string` value.

<br>

Argument: `string` value.

||


|#

## Mathematical operations {#math}

Mathematical operations

#|
||
**Function**
|
**Description**
||

||
`div(integer, integer) integer`
|
Calculates the quotient of the first number divided by the second. Rounds down the result. For example: `div(5,2)` → `2`.
Returns an `integer`.

<br>

Arguments: 1 — `integer` dividend. 2 — `integer` divisor.

||

||
`div(number, number) number`
|
Calculates the quotient of the first number divided by the second.
Returns a `number`.

<br>

Arguments: 1 — `number` dividend. 2 — `number` divisor.

||

||
`mod(integer, integer) integer`
|
Calculates the remainder of the first number divided by the second.
Returns an `integer`.

<br>

Arguments: 1 — `integer` dividend. 2 — `integer` divisor.

||

||
`mul(vararg integer) integer`
|
Calculates the product of the arguments.
Returns an `integer`.

<br>

Arguments: multiple `integer` values.

||

||
`mul(vararg number) number`
|
Calculates the product of the arguments.
Returns a `number`.

<br>

Arguments: Multiple `number` values.

||

||
`sub(vararg integer) integer`
|
Calculates the difference of the arguments.
Returns an `integer`.

<br>

Arguments: 1 — `integer` value to subtract the other arguments from. Other arguments — One or more `integer` values to be subtracted from Argument 1.

||

||
`sub(vararg number) number`
|
Calculates the difference of the arguments.
Returns a `number`.

<br>

Arguments: 1 — `number` value to subtract the other arguments from. Other arguments — One or more `number` values to be subtracted from Argument 1.

||

||
`sum(vararg integer) integer`
|
Calculates the sum of the arguments.
Returns an `integer`.

<br>

Arguments: multiple `integer` values.

||

||
`sum(vararg number) number`
|
Calculates the sum of the arguments.
Returns a `number`.

<br>

Arguments: Multiple `number` values.

||

||
`abs(number) number`
|
Calculates the absolute value of the argument.
Returns a `number`.

<br>

Argument: `number` value.

||

||
`abs(integer) integer`
|
Calculates the absolute value of the argument.
Returns an `integer`.

<br>

Argument: `integer` value.

||

||
`max(vararg number) number`
|
Finds the argument with the highest value.
Returns a `number`.

<br>

Arguments: Multiple `number` values.

||

||
`max(vararg integer) integer`
|
Finds the argument with the highest value.
Returns an `integer`.

<br>

Arguments: multiple `integer` values.

||

||
`min(vararg integer) integer`
|
Finds the argument with the lowest value.
Returns an `integer`.

<br>

Arguments: multiple `integer` values.

||

||
`min(vararg number) number`
|
Finds the argument with the lowest value.
Returns a `number`.

<br>

Arguments: Multiple `number` values.

||

||
`maxNumber() number`
|
Finds the `number` argument with the highest value.
Returns a `number`.

No arguments.

||

||
`maxInteger() integer`
|
Finds the `integer` argument with the highest value.
Returns an `integer`.

No arguments.

||

||
`minNumber() number`
|
Finds the `number` argument with the lowest value.
Returns a `number`.

No arguments.

||

||
`minInteger() integer`
|
Finds the `integer` argument with the lowest value.
Returns an `integer`.

No arguments.

||

||
`round(number) number`
|
Rounds the argument. For example, 1.49 → 1.0, 1.5 → 2.0.
Returns a `number`.

<br>

Argument: `number` value.

||

||
`floor(number) number`
|
Rounds the argument down. For example, 1.49 → 1.0, 1.5 → 1.0.
Returns a `number`.

<br>

Argument: `number` value.

||

||
`ceil(number) number`
|
Rounds the argument up. For example, 1.49 → 2.0, 1.5 → 2.0.
Returns a `number`.

<br>

Argument: `number` value.

||

||
`signum(number) number`
|
Finds the sign of the argument.
Returns `-1.0` for negative values, `0.0` for zero, and `1.0` for positive values.

<br>

Argument: `number` value.

||

||
`signum(integer) integer`
|
Finds the sign of the argument.
Returns `-1` for negative values, `0` for zero, and `1` for positive values.

<br>

Argument: `integer` value.

||

||
`copySign(number, number) number`
|
Gets the number with the magnitude of the first argument and the sign of the second argument.
Returns a `number`.

<br>

Arguments: 1 — `number` value to copy the magnitude from. 2 — `number` value to copy the sign from.

||

||
`copySign(integer, integer) integer`
|
Gets the number with the magnitude of the first argument and the sign of the second argument.
Returns an `integer`.

<br>

Arguments: 1 — `integer` value to copy the magnitude from. 2 — `integer` value to copy the sign from.

||


||
`pi() number`
|
Returns value of the `π`: ratio of the circumference of a circle to its diameter.
Returns a value of type `number`.

Platforms: \[Android]

||


||
`toRadians(number) number`
|
Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
Returns a value of type `number`.

Platforms: \[Android]

<br>

Argument: angle in degrees (`number` value).

||


||
`toDegrees(number) number`
|
Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
Returns a value of type `number`.

Platforms: \[Android]

<br>

Argument: angle in radians (`number` value).

||


||
`sin(number) number`
|
Calculates the sine of the given angle in radians.

<br>

Argument: angle in radians.

||


||
`cos(number) number`
|
Calculates the cosine of the given angle in radians.

<br>

Argument: angle in radians.

||


||
`tan(number) number`
|
Calculates the tangent of the given angle in radians.

<br>

Argument: angle in radians.

||


||
`asin(number) number`
|
Calculates the angle in radians of the given sine value. Argument value must fall within the range [-1, 1], otherwise the function will fail.

<br>

Argument: sine value.

||


||
`acos(number) number`
|
Calculates the angle in radians of the given cosine value. Argument value must fall within the range [-1, 1], otherwise the function will fail.

<br>

Argument: cosine value.

||


||
`atan(number) number`
|
Calculates the angle in radians of the given tangent value.

<br>

Argument: tangent value.

||


||
`atan2(number, number) number`
|
Calculates the angle in radians between the positive x-axis and the point given by the coordinates (x, y).

<br>

Arguments: 1 — `number` value representing the y-coordinate. 2 — `number` value representing the x-coordinate.

||

|#

## String operations {#strings}

#|
||
**Function**
|
**Description**
||

||
`len(string) integer`
|
Gets the length of the specified string.
Returns an `integer`.

<br>

Argument: `string` value.

||

||
`contains(string, string) boolean`
|
Determines whether the string (Argument 1) contains the specified substring (Argument 2).
Returns a `boolean`.

<br>

Arguments: 1 — Source `string` to search. 2 — `string` substring to search for.

||

||
`substring(string, integer, integer) string`
|
Gets the part of the string (Argument 1) located in the range defined by Arguments 2 and 3.
Returns a `string`.

<br>

Arguments: 1 — Source `string`. 2 — `integer` value of the copied substring's left index. 3 — `integer` value of the copied substring's right index.

||

||
`replaceAll(string, string, string) string`
|
Finds and replaces all occurrences of the substring (Argument 2) in the source string (Argument 1) with the string specified in Argument 3.
Returns a `string` copy of the source string with all the matches replaced.

<br>

Arguments: 1 — Source `string` to search. 2 — `string` substring to search for. 3 — Replacement `string`.

||

||
`index(string, string) integer`
|
Gets the index of the first occurrence of the substring (Argument 2) in the string (Argument 1).
Returns an `integer`: the index of the first occurrence or `-1` if the substring is not found.

<br>

Arguments: 1 — Source `string` to search. 2 — `string` substring to search for.

||

||
`lastIndex(string, string) integer`
|
Gets the index of the last occurrence of the substring (Argument 2) in the string (Argument 1).
Returns an `integer`: the index of the last occurrence or `-1` if the substring is not found.

<br>

Arguments: 1 — Source `string` to search. 2 — `string` substring to search for.

||

||
`trim(string) string`
|
Trims whitespace from both ends of the specified string.
Returns a `string`.

<br>

Argument: `string` value.

||

||
`trimLeft(string) string`
|
Trims whitespace from the beginning of the specified string.
Returns a `string`.

<br>

Argument: `string` value.

||

||
`trimRight(string) string`
|
Trims whitespace from the end of the specified string.
Returns a `string`.

<br>

Argument: `string` value.

||

||
`toUpperCase(string) string`
|
Converts the specified string to uppercase.
Returns a `string`.

<br>

Argument: `string` value.

||

||
`toLowerCase(string) string`
|
Converts the specified string to lowercase.
Returns a `string`.

<br>

Argument: `string` value.

||

||
`padStart(string, integer, string) string`
|
Pads the beginning of the string with the specified characters until it reaches the specified length.
Returns a `string`.

<br>

Arguments: 1 — Source `string`. 2 — `integer` value of the required string length. 3 — `string` to pad the beginning of the source string with.

<br>

For example: `"@{padStart('0', 4, '12')}"` → `"1210"`

||

||
`padStart(integer, integer, string) string`
|
Converts the number to a string and pads the beginning of the resulting string with the specified characters until it reaches the specified length.
Returns a `string`.

<br>

Arguments: 1 — Source `integer`. 2 — `integer` value of the required string length. 3 — `string` to pad the beginning of the resulting string with.

<br>

For example: `"@{padStart(0, 4, '12')}"` → `"1210"`

||

||
`padEnd(string, integer, string) string`
|
Pads the end of the string with the specified characters until it reaches the specified length.
Returns a `string`.

<br>

Arguments: 1 — Source `string`. 2 — `integer` value of the required string length. 3 — `string` to pad the end of the source string with.

<br>

For example: `"@{padEnd('0', 4, '12')}"` → `"0121"`

||

||
`padEnd(integer, integer, string) string`
|
Converts the number to a string and pads the end of the resulting string with the specified characters until it reaches the specified length.
Returns a `string`.

<br>

Arguments: 1 — Source `integer`. 2 — `integer` value of the required string length. 3 — `string` to pad the end of the resulting string with.

<br>

For example: `"@{padEnd(0, 4, '12')}"` → `"0121"`

||


|#

## Color operations {#colors}

#|
||
**Function**
|
**Description**
||

||
`getColorAlpha(string) number`
|
Gets the alpha component of the specified color.
Returns a `number` in the range from `0.0` to `1.0`.

<br>

Argument: `string` hex color value.

||

||
`getColorRed(string) number`
|
Gets the red component of the specified color.
Returns a `number` in the range from `0.0` to `1.0`.

<br>

Argument: `string` hex color value.

||

||
`getColorGreen(string) number`
|
Gets the green component of the specified color.
Returns a `number` in the range from `0.0` to `1.0`.

<br>

Argument: `string` hex color value.

||

||
`getColorBlue(string) number`
|
Gets the blue component of the specified color.
Returns a `number` in the range from `0.0` to `1.0`.

<br>

Argument: `string` hex color value.

||

||
`setColorAlpha(string, number) string`
|
Sets the alpha value of the specified color.
Returns a `string` hex color value. For example, `'#FFAABBCC'`.

<br>

Arguments: 1 — `string` hex color value. 2 — `number` alpha value in the range from `0.0` to `1.0`.

||

||
`setColorRed(string, number) string`
|
Sets the red value of the specified color.
Returns a `string` hex color value. For example, `'#FFAABBCC'`.

<br>

Arguments: 1 — `string` hex color value. 2 — `number` red value in the range from `0.0` to `1.0`.

||

||
`setColorGreen(string, number) string`
|
Sets the green value of the specified color.
Returns a `string` hex color value. For example, `'#FFAABBCC'`.

<br>

Arguments: 1 — `string` hex color value. 2 — `number` green value in the range from `0.0` to `1.0`.

||

||
`setColorBlue(string, number) string`
|
Sets the blue value of the specified color.
Returns a `string` hex color value. For example, `'#FFAABBCC'`.

<br>

Arguments: 1 — `string` hex color value. 2 — `number` blue value in the range from `0.0` to `1.0`.

||

||
`argb(number, number, number, number) string`
|
Creates a hex color code with the specified alpha, red, green, and blue values.
Returns a `string` hex color value. For example, `'#FFAABBCC'`.

<br>

Arguments: 1 — `number` alpha value in the range from `0.0` to `1.0`. 2 — `number` red value in the range from `0.0` to `1.0`. 3 — `number` green value in the range from `0.0` to `1.0`. 4 — `number` blue value in the range from `0.0` to `1.0`.

||

||
`rgb(number, number, number) string`
|
Creates a hex color code with the specified red, green, and blue values. Sets the alpha component value to `1.0`.
Returns a `string` hex color value. For example, `'#FFAABBCC'`.

<br>

Arguments: 1 — `number` red value in the range from `0.0` to `1.0`. 2 — `number` green value in the range from `0.0` to `1.0`. 3 — `number` blue value in the range from `0.0` to `1.0`.

||


|#

## Date and time operations {#datetime}

#|
||
**Function**
|
**Description**
||

||
`parseUnixTime(integer) datetime`
|
Creates a datetime value from the specified Unix timestamp.
Returns a `datetime`.

<br>

Argument: `integer` number of seconds elapsed since midnight, January 1, 1970, UTC.

||

||
`nowLocal() datetime`
|
Creates a datetime value for the current time.
Returns a `datetime`.

No arguments.

||

||
`addMillis(datetime, milliseconds: integer) datetime`
|
Adds the specified number of milliseconds to the original datetime.
Returns a `datetime`.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` number of milliseconds to add.

||

||
`setYear(datetime, year: integer) datetime`
|
Sets the year value of the original datetime.
Returns a `datetime` with the specified year value.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` year value.

||

||
`setMonth(datetime, month: integer) datetime`
|
Sets the month value of the original datetime.
Returns a `datetime` with the specified month value.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` month value from `1` to `12`.

||

||
`setDay(datetime, monthDay: integer) datetime`
|
Sets the day of month value of the original datetime.
Returns a `datetime` with the specified day of month value.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` day of month value.

||

||
`setHours(datetime, hours: integer) datetime`
|
Sets the hours value of the original datetime.
Returns a `datetime` with the specified hours value.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` hours value.

||

||
`setMinutes(datetime, minutes: integer) datetime`
|
Sets the minutes value of the original datetime.
Returns a `datetime` with the specified minutes value.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` minutes value.

||

||
`setSeconds(datetime, seconds: integer) datetime`
|
Sets the seconds value of the original datetime.
Returns a `datetime` with the specified seconds value.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` seconds value.

||

||
`setMillis(datetime, milliseconds: integer) datetime`
|
Sets the milliseconds value of the original datetime.
Returns a `datetime` with the specified milliseconds value.

<br>

Arguments: 1 — Original `datetime`. 2 — `integer` milliseconds value.

||

||
`getYear(datetime) integer`
|
Gets the year value of the original datetime.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getMonth(datetime) integer`
|
Gets the month number value of the original datetime.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getDay(datetime) integer`
|
Gets the day of month value of the original datetime.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getDayOfWeek(datetime) integer`
|
Gets the day of week value of the original datetime, where `7` is Sunday.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getHours(datetime) integer`
|
Gets the hours value of the original datetime.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getMinutes(datetime) integer`
|
Gets the minutes value of the original datetime.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getSeconds(datetime) integer`
|
Gets the seconds value of the original datetime.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getMillis(datetime) integer`
|
Gets the milliseconds value of the original datetime.
Returns an `integer`.

<br>

Argument: Original `datetime`.

||

||
`getIntervalSeconds(integer) integer`
|
Converts the interval in milliseconds to `Dd HH:MM:SS` format (days, hours, minutes, seconds) and gets its seconds value.
Returns an `integer` in the range from `0` to `59`.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalSeconds(100000000)}` → `40`
||

||
`getIntervalTotalSeconds(integer) integer`
|
Converts the interval in milliseconds to seconds and rounds the result down.
Returns an `integer` seconds value.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalTotalSeconds(100000000)}` → `100000`
||

||
`getIntervalMinutes(integer) integer`
|
Converts the interval in milliseconds to `Dd HH:MM:SS` format (days, hours, minutes, seconds) and gets its minutes value.
Returns an `integer` in the range from `0` to `59`.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalMinutes(100000000)}` → `46`
||

||
`getIntervalTotalMinutes(integer) integer`
|
Converts the interval in milliseconds to minutes and rounds the result down.
Returns an `integer` minutes value.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalTotalMinutes(100000000)}` → `1666`
||

||
`getIntervalHours(integer) integer`
|
Converts the interval in milliseconds to `Dd HH:MM:SS` format (days, hours, minutes, seconds) and gets its hours value.
Returns an `integer` in the range from `0` to `23`.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalHours(100000000)}` → `3`
||

||
`getIntervalTotalHours(integer) integer`
|
Converts the interval in milliseconds to hours and rounds the result down.
Returns an `integer` hours value.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalTotalHours(100000000)}` → `27`
||

||
`getIntervalTotalDays(integer) integer`
|
Converts the interval in milliseconds to days and rounds the result down.
Returns an `integer` day value.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalTotalDays(1000000000)}` → `11`
||

||
`getIntervalTotalWeeks(integer) integer`
|
Converts the interval in milliseconds to weeks and rounds the result down.
Returns an `integer` week value.

<br>

Argument: `integer` interval duration in milliseconds.
<br>

For example, `@{getIntervalTotalWeeks(1000000000)}` → `1`
||


||
`getTimestamp(datetime) integer`
|
Converts a DateTime object to a timestamp in milliseconds.
Returns an `integer` value.

<br>

Argument: date and time value, `datetime` type.
||

|#

<!-- source: en/_includes/index/troubleshooting.md -->
## Learn more {#troubleshooting}

You can discuss topics of interest in the DivKit user community in Telegram: [https://t.me/divkit_community_en](https://t.me/divkit_community_en).



[DivKit Repository](https://github.com/divkit/divkit)
<!-- endsource: en/_includes/index/troubleshooting.md -->

