# Calculations & Formulas

User can enter a formula by clicking the formula input box. Whatever is entered in the formula input box will be saved in the format $fn{formula}. The formula can contain constants, variables, operators, and functions.&#x20;

<figure><img src="https://640808362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5jDaQI2dLzXe5VgQBNFE%2Fuploads%2FCmddnwGdZRSaVyX6r9mq%2FGitbook-switch%20fields1.jpg?alt=media&#x26;token=1ecc8ecf-3051-4cac-b41d-13ec5b4db943" alt=""><figcaption></figcaption></figure>

#### <mark style="color:purple;">Operators</mark>

* +, -, \*, /, % (modulus), ^ (exponent)   -> + works with strings and numbers while others will work with numbers only
* \| (pipe) can be used to pass the result of the left-hand side expression as the first argument of the right-hand side expression.

#### <mark style="color:purple;">Functions</mark>

User's can view all the supported functions by typing '@'. The supported functions are&#x20;

**Number Functions**

* @sum(\[n1, n2, …]): Calculates the sum of the given numbers or variables.
* @max(\[n1, n2, …]): Finds the maximum value among the given numbers or variables.
* @min(\[n1, n2, …]): Finds the minimum value among the given numbers or variables.
* @mean(\[n1, n2, …]): Calculates the mean (average) of the given numbers or variables.
* @median(\[n1, n2, …]): Finds the median value among the given numbers or variables.
* @abs(n): Returns the absolute value of the given number or variables.

**String Functions**

* @trim(str, chars): Removes specified characters from the start and end of a string.
* @trimPrefix(str, prefix): Removes a specified prefix from the start of a string.
* @trimSuffix(str, suffix): Removes a specified suffix from the end of a string.
* @upper(str): Converts a string to uppercase.
* @lower(str): Converts a string to lowercase.
* @split(str, delimiter, n): Splits a string into an array of substrings based on a specified delimiter, with an optional limit on the number of splits.
* @splitAfter(str, delimiter, n): Splits a string into an array of substrings based on a specified delimiter, with an optional limit on the number of splits, and includes the delimiter in each substring.
* @replace(str, old, new): Replaces occurrences of a specified substring with a new substring in a string.
* @repeat(str, n): Repeats a string a specified number of times.
* @indexOf(str, substring): Returns the index of the first occurrence of a specified substring in a string.
* @lastIndexOf(str, substring): Returns the index of the last occurrence of a specified substring in a string.

**Type Conversion**

* @type(v): Returns the data type of the value 'v'.
* @int(v): Converts the value 'v' to an integer.
* @float(v): Converts the value 'v' to a floating-point number.
* @string(v): Converts the value 'v' to a string.
* @toJSON(v): Converts the value 'v' to a JSON string.
* @fromJSON(v): Converts the JSON string 'v' to its corresponding value.

**Miscellaneous**

* @len(v): Returns the length of an array or string
