Numbers and math
Learn how to summarize values, convert data to numbers, generate ranges, and use common math functions in Ninox scripts.
Numbers drive many Ninox apps. You use them for prices, quantities, ratings, durations, percentages, and all kinds of calculations.
abs()
Remove the sign from a number
acos()
Calculate the arccosine of a number
asin()
Calculate the arcsine of a number
atan()
Calculate the arctangent of a number
atan2()
Return the arctangent of a quotient
avg()
Calculate the average of numeric values
ceil()
Round a number up to the next integer
cos()
Calculate the cosine of an angle
degrees()
Convert radians to degrees
even()
Check if a number is even
exp()
Calculate the natural exponential function
floor()
Round a number down to the next integer
ln()
Calculate the natural logarithm
log()
Calculate a logarithm with base 10 or another base
max()
Return the highest or latest value
min()
Return the lowest or earliest value
number()
Convert a value to a number or return the ID from a choice field
numbers()
Return IDs from a multiple choice field
odd()
Check if a number is odd
pow()
Raise a number to a power
random()
Generate a random number between 0 and 1
radians()
Convert degrees to radians
range()
Build an array of consecutive numbers
round()
Round a number to an integer or decimal place
sign()
Return whether a number is negative, zero, or positive
sin()
Calculate the sine of an angle
sqr()
Square a number
sqrt()
Take the square root of a number
sum()
Add numeric values together
tan()
Calculate the tangent of an angle
Calculate averages, sums, minimums, and maximums
Use avg(), sum(), min(), and max() to summarize numeric values from arrays, record selections, or computed lists. These functions are useful for totals, KPIs, date ranges, and quick checks in formula fields.
Average values with avg()
avg()Use avg() to calculate the mathematical average of numeric values from an array or a table selection.
avg([number])
[number]: an array of numbers, or a list of numeric field values
avg() returns one numeric result for the values you pass in.
You can use avg() with:
arrays of numbers
columns in table views that contain numeric values
Let’s take a look at some examples:
Calculates the average of the numbers 1 through 9.
The script returns 5.
Takes all records from the "Invoices" table and calculates the average of the field "Total".
Calculates the average payment duration across the selected invoices, if payment_duration is a numeric field.
Tip:
Use
avg()only with numeric values.
Sum values with sum()
sum()Use sum() to add numeric values from an array or a table selection.
Use it when you want to:
Total invoice amounts, budgets, or payments, or KPI fields.
Add up hours from related records.
sum([number])
[number]: an array of numbers, or a list of numeric field values
Let's take a look at some examples:
Adds the numbers 1 through 9.
The script returns 45.
Sums the field "Total" across all records in the table "Invoices".
Filters invoices to 2025 and sums only those totals.
Find the lowest or earliest value with min()
min()Use min() to return the lowest number or the earliest date or timestamp in a list.
min([any])
[any]: an array of comparable values, typically numbers, dates, or timestamps
min() returns one value from the list.
The result keeps the same type as the values you pass in:
lowest value for numeric arrays
earliest value for date or timestamp arrays
Use min() only with values that can be compared meaningfully, such as numbers or time-related values.
Let’s take a look at some examples:
Returns the lowest number in the list.
The script returns 1.
The first line stores the current year from now() in a variable. The second line builds a list of birthdays in that year. The last line returns the earliest date in the list.
Find the highest or latest value with max()
max()Use max() to return the highest number or the latest date or timestamp in a list.
max([any])
[any]: an array of comparable values, typically numbers, dates, or timestamps
max() returns one value from the list.
The result keeps the same type as the values you pass in:
highest value for numeric arrays
latest value for date or timestamp arrays
Use max() only with values that can be compared meaningfully, such as numbers or time-related values.
Let’s take a look at some examples:
Returns the highest number in the list.
The script returns 35.
The first line stores the current year from now() in a variable. The second line builds a list of birthdays in that year. The last line returns the latest date in the list.
Tips:
Use
avg()andsum()for numeric values only.Use
min()andmax()for both numbers and time-based values.
Round numbers up, down, or to a chosen precision
Use these functions when you want cleaner output, whole numbers, or fixed decimal precision.
Round up with ceil()
ceil()Use ceil() to round a decimal number up to the next higher integer.
Use it when you want to:
Round quantities, pages, or package counts up.
Remove decimals and always move to the next full number.
ceil(number)
number: the value you want to round up
If the input is already an integer, the value stays unchanged.
Let’s take a look at some examples:
Returns 3.
Returns 13.
Returns 27.
Tips:
Use
ceil()when partial values should count as the next whole unit.
Round down with floor()
floor()Use floor() to round a decimal number down to the next lower integer.
Use it when you want to:
Remove decimals without increasing the value.
Round durations, quantities, or scores down.
floor(number)
number: the value you want to round down
If the input is already an integer, the value stays unchanged.
Let’s take a look at some examples:
Returns 2.
Returns 12.
Returns 27.
Tips:
Use
floor()when you need completed whole units only.
Round to an integer or decimal place with round()
round()Use round() to round a number to the nearest integer or to a chosen number of decimal places.
Use it when you want to:
Show cleaner amounts in reports or forms.
Limit decimal places for prices, rates, or percentages.
Apply standard commercial rounding.
round(number)
round(number, digits)
number: the value you want to rounddigits: the number of decimal places to keep
round() uses standard commercial rounding:
5or more rounds up4or less rounds down
If you omit digits, Ninox rounds to the nearest integer.
Let’s take a look at some examples:
Returns 3.
Returns 12.
Returns 12.49.
Returns 1.7.
Tips:
Use
round(number)when you want a whole number.Use
round(number, digits)when display precision matters.Use
format()after rounding when the result also needs a fixed visual format.
Create random numbers and ranges
Use random() to generate test values or percentages. Use range() to build arrays of consecutive numbers you can loop through or map over.
Create random numbers with random()
random()Use random() to generate a random number between 0 and 1.
Use it when you want to:
Generate values for passwords, check digits, or ID-like helpers.
Simulate percentages or probabilities.
Build non-linear test runs or quiz logic.
The result is always:
Greater than or equal to
0Less than
1
Let’s take a look at some examples:
Returns a random number between 0 and 1.
Example result: 0.0817465303933449.
Returns a whole number between 0 and 9.
Returns a random number between 0 and 100 with two decimal places.
If the randomly given number is 0.071249890 the result is 7.12.
Build arrays of numbers with range()
range()Use range() to build an array of consecutive numbers.
Use it when you want to:
Loop through months, days, or index positions.
Generate helper arrays for repeated calculations.
When you pass only one parameter, Ninox starts at 0.
The start value is included. The end value is excluded.
If from is greater than to, Ninox returns the numbers in reverse order.
range(to)
range(from, to)
range(from, to, step)
from: the first number in the listto: the point where Ninox stopsstep: how much to add or subtract each time
Let’s take a look at some examples:
Creates the array [0, 1, 2, 3, 4, 5, 6].
Creates the array [2, 3, 4, 5, 6].
Creates the array [7, 6, 5, 4, 3].
Counts up in steps of 2.
The result is [2, 4, 6, 8].
Tip:
The
tovalue is not included.
Convert values to numbers with number() and numbers()
number() and numbers()Use number() to convert one value to a number or return the internal ID of a value from a choice field. Use numbers() to return the internal IDs from multiple choice fields.
Turn a value into a number with number()
number()Use number() when a field type must become numeric before you calculate with it.
Use it when you want to:
Turn imported text like
"1250"into a usable amount.Compare or calculate with values from choice fields, as the displayed values of choice fields are always text.
Convert date or duration values before advanced calculations.
Depending on the input:
textthat contains digits only become a number.Dates,timestamps,time intervals, ortimevalues become numeric values which represents milliseconds.choice fieldsreturn the numeric ID of the selected option.
number(any)
any: the value you want to convert to a number
number() returns one numeric result.
Let’s take a look at some examples:
Converts today’s date to a numeric Unix time value in milliseconds.
Converts digit-only text into a number.
The script returns 75639.
If priority is a choice field, this returns the numeric value of the selected option.
Converts the start of the appointment to a numeric Unix time value in milliseconds.
Converts the end of the appointment to a numeric Unix time value in milliseconds.
Converts imported text in quantity_as_text before multiplying it with unit_price.
Get IDs from multiple choice fields with numbers()
numbers()Use numbers() to return the IDs of the selected values in a multiple choice field.
Use it when you want to:
Reuse selected IDs in filtering logic.
numbers() returns an array of numeric IDs.
numbers(multi)
Let’s take a look at some examples:
Assume the multiple choice field favorite_sports has these selected items:
Basketball, ID
1Dancing, ID
3Sailing, ID
4Soccer, ID
5
Returns the internal IDs of the selected items: [1, 3, 4, 5].
Checks whether the option with ID 3 is selected.
Tips:
Use
number()before math operations when the source value is still text.Use
numbers()when you need IDs for filtering or comparisons.Do not confuse
number()andnumbers(). One converts a value. The other returns a list of IDs.
Check if a number is even, odd, or its sign
Use even(), odd(), and sign() to test simple number properties. These functions are useful in conditions, formatting rules, and branching logic.
Check if a number is even with even()
even()Use even() to check whether a number can be divided by 2 without a remainder.
Use it when you want to:
Stripe rows in a table view.
Split records into alternating groups.
Trigger logic every second item in a loop.
even(number)
number: the value you want to test
even() returns a boolean value:
trueif the number is evenfalseif the number is not even
0 counts as an even number. For decimal values, even() returns true only if the value is divisible by 2 without a remainder.
Let’s take a look at some examples:
Returns true because 6 is even.
Returns false because 7 is not even.
Returns true because the result is 22, which is even.
Returns true because 0 is even.
Returns false because 10.2 is not divisible by 2 without a remainder.
Uses even() in a condition to alternate row colors.
Check if a number is odd with odd()
odd()Use odd() to check whether a number is not divisible by 2 without a remainder.
Use it when you want to do the same like with even() but for odd numbers.
odd(number)
number: the value you want to test
odd() returns a boolean value:
trueif the number is oddfalseif the number is not odd
0 is even, so odd(0) returns false. For decimal values, odd() returns true when the value is not divisible by 2 without a remainder.
Let’s take a look at some examples:
Returns true because 5 is odd.
Returns false because 10 is not odd.
Returns false because the result is 22, which is even.
Returns false because 0 is even.
Returns true because 10.2 is not divisible by 2 without a remainder.
Shows a marker for odd rows only.
Get the sign of a number with sign()
sign()Use sign() to check whether a number is negative, zero, or positive.
Use it when you want to:
Label balances as debit, zero, or credit.
Classify stock changes as incoming or outgoing.
Branch logic based on gain versus loss.
sign(number)
number: the value you want to check
sign() returns:
-1for negative values1for zero and positive values
Let’s take a look at some examples:
Returns -1 because -5 is negative.
Returns 1 because 0 is treated as positive.
Returns 1 because 12.7 is positive.
Branches your logic based on whether the value is negative or not.
Tips:
Use
sign()when the direction of a value matters more than its size.Remember:
0is treated as positve and even number.
Work with absolute values, powers, roots, and logarithms
Use these functions for more advanced calculations with distances, growth, exponents, or ratios.
abs()removes the sign from a number.sqr()andsqrt()square a number or take its square root.pow()raises a number to any exponent.exp()calculates the natural exponential function.ln()andlog()calculate logarithms.
Get a positive value with abs()
abs()Use abs() when you need the size of a number but not its sign. It returns the absolute value of a number.
Use it when you want to:
Show the distance between two numbers.
Compare deviations without caring which side is bigger.
abs(number)
number: the numeric value you want without a sign
abs() returns:
the same value for positive numbers
0for zerothe positive version of a negative number
Let’s take a look at some examples:
Removes the minus sign and returns 9.3.
Leaves the value unchanged and returns 9.3.
Returns 0.
Returns the deviation between actual and planned hours as a positive number.
Returns the difference as a positive value, even if costs are higher than income.
Square a number with sqr()
sqr()Use sqr() to multiply a number by itself.
The result is always positive.
sqr(number)
number: the value you want to square
Let’s take a look at some examples:
Calculates 3 * 3 and returns 9.
Calculates (-3) * (-3) and returns 9.
First calculates -3. Then it squares the result and returns 9.
Take the square root with sqrt()
sqrt()Use sqrt() to calculate the square root of a positive number.
If the input might be negative, convert it first. A common pattern is sqrt() with abs().
sqrt(number)
number: the value you want the square root of
Let’s take a look at some examples:
Returns 1.7320508075688772.
Returns 3.
Returns an invalid result because the input is negative.
First turns -4 into 4. Then it returns 2.
Raise a number to a power with pow()
pow()Use pow() to raise a base number to any exponent.
Use it when you want to:
Build formulas where the exponent changes.
pow(base, exponent)
base: the base numberexponent: the power to apply
If you use a fractional exponent, pow() returns the matching root:
0.5returns the square root1 / 3returns the cube root
With fractional exponents, the result can be a close approximation instead of a perfectly rounded value. This is normal for floating-point calculations.
Let’s take a look at some examples:
Calculates 4 to the power of 3.
The result is 64.
Uses the exponent 0.5, which is equivalent to the square root.
The result is 8.
Calculates the cube root of 64.
The result can be 3.9999999999999996 instead of exactly 4 because of floating-point precision.
In such cases combine pow() with round().
Calculates 12 periods of 5% compound growth.
Use the natural exponential function with exp()
exp()Use exp() when you need Euler’s number e raised to a power.
Use it when you want to:
Apply advanced scoring formulas.
Reverse calculations that use
ln().
exp(number)
number: the exponent
exp() calculates the natural exponential function with Euler’s number e as the base.
Let’s take a look at some examples:
Calculates e^1.
The result is 2.718281828459045.
Returns 1.
First calculates 3. Then it returns e^3, which is 20.085536923187668.
Calculate the natural logarithm with ln()
ln()Use ln() to calculate the natural logarithm of a number. This is the logarithm to the base e.
Use it when you want to:
Reverse a calculation that used
exp().Compress very large ranges of values.
Use advanced formulas for growth or normalization.
ln(number)
number: the value you want the logarithm of
ln() returns one numeric result.
For ln():
Positive values return a real number.
0returns-∞.Negative values are invalid.
Let’s take a look at some examples:
Returns 0 because e^0 = 1.
Returns -∞.
Returns 4.605170185988092.
Returns a value close to 3.
Calculate logarithms with other bases using log()
log()Use log() when you need a logarithm with base 10 or another base.
Use it when you want to:
Reduce large values to a smaller scale.
Work with formulas that use base 10 or custom bases.
log(number)
log(number, number)
first
number: the value you want the logarithm ofsecond
number: the base. If you skip it, Ninox uses base10
For log():
Positive values return a real number.
0returns-∞.Negative values are invalid.
Let’s take a look at some examples:
Returns 0 with the default base 10.
Returns -∞.
Calculates the logarithm of 3 to base 5.
The result is 0.6826061944859853.
Compresses large follower counts so they are easier to compare in a score.
Tips:
Use
pow()when the exponent is variable.Use
exp(),ln(), andlog()only when your formula actually needs them. They are less common in everyday app logic.
Calculate sine, cosine, and tangent
Use these functions when you want to work with angles directly in trigonometric formulas.
Calculate the cosine with cos()
cos()Use cos() to return the cosine of an angle in radians.
Use it when you want to:
Convert an angle into a cosine value.
Reuse trigonometric values in calculations.
cos(number)
number: the angle in radians
cos() returns a number between -1 and 1.
Let’s take a look at some examples:
Returns 0.9689124217106447.
Tips:
cos()expects radians, not degrees.Use
degrees()orradians()when you need to convert angle units first.
Calculate the sine with sin()
sin()Use sin() to return the sine of an angle.
Use it when you want to:
Convert an angle into a sine value.
sin(number)
number: the angle value
sin() returns a number between -1 and 1.
Let’s take a look at some examples:
Returns -0.24740395925452294.
Returns 0.8414709848078965.
Tip:
Convert the input first if your source angle is stored in degrees.
Calculate the tangent with tan()
tan()Use tan() to return the tangent of an angle.
Use it when you want to:
Work with angle-based calculations from one value.
tan(number)
number: the angle value
Let’s take a look at some examples:
Returns 1.5574077246549023.
Returns 14.101419947171719.
Returns -3.380515006246586.
Tip:
Convert the input first if your source angle is stored in degrees.
Convert angles between radians and degrees
Use these functions when your formula needs a different angle unit than the source value provides.
Convert radians to degrees with degrees()
degrees()Use degrees() to convert an angle from radians to degrees.
Use it when you want to:
Prepare trigonometric output for people who expect degrees.
Convert results before further angle-based logic.
degrees(number)
number: the angle in radians
Let’s take a look at some examples:
Returns 180.
Tips:
Use
degrees()when the source value is already in radians.This is especially useful after trigonometric calculations that return radian values.
Convert degrees to radians with radians()
radians()Use radians() to convert an angle from degrees to radians.
Use it when you want to:
Prepare degree values for trigonometric functions.
Standardize angle input before
sin(),cos(), ortan().
radians(number)
number: the angle in degrees
Let’s take a look at some examples:
Returns 3.141592653589793.
Tips:
Use
radians()beforesin(),cos(), andtan()when the input is stored in degrees.Keep angle units consistent across the whole formula.
Use inverse trigonometric functions
Use these functions when you need to derive an angle from a numeric value or quotient.
Calculate the arccosine with acos()
acos()Use acos() to return the arccosine of a number.
Use it when you want to:
Convert a cosine value into an angle.
Work with geometry or angle-based formulas.
acos(number)
number: the value for which you want the arccosine
Let’s take a look at some examples:
Returns 1.8234765819369754.
Tip:
Use
acos()only with values from-1to1. Values outside that range do not return a valid result.
Calculate the arcsine with asin()
asin()Use asin() to return the arcsine of a number.
Use it when you want to:
Convert a sine value into an angle.
Build angle-based formulas from normalized values.
asin(number)
number: the value for which you want the arcsine
Let’s take a look at some examples:
Returns -0.25268025514207865.
Returns 1.5707963267948966.
Returns an invalid result because the input is outside the valid range.
Tip:
Use
asin()only with values from-1to1. If you are unsure about the range, check imported or calculated values first.
Calculate the arctangent with atan()
atan()Use atan() to return the arctangent of a number.
Use it when you want to:
Convert a tangent value into an angle.
Build geometry or direction formulas from a ratio.
atan(number)
number: the value for which you want the arctangent
Let’s take a look at some examples:
Returns 1.5042281630190728.
Tips:
Use
atan()when you already have one numeric value or ratio.Use
atan2()when the quotient comes from two separate values.
Return the arctangent of a quotient with atan2()
atan2()Use atan2() to return the arctangent of the quotient of two numbers.
Use it when you want to:
Calculate an angle from two values.
Avoid calculating the quotient first in a separate step.
atan2(number, number)
first
number: the numerator valuesecond
number: the denominator value
atan2() returns one number.
Let’s take a look at some examples:
Returns 1.0516502125483738.
Tips:
Use
atan2()when your formula starts with two separate values.Use
atan()when you already have the final quotient as one number.
Last updated
Was this helpful?