Numeric functions
characterFrom(int value)
- Returns a string by constructing an ASCII number from the given integer
def string value = characterFrom(65); // value = A
def string value2 = (65).characterFrom(); // value2 = A
Make sure to give input in correct range or you might get an error
PI()
- Returns the mathematical constant Pi
def real pi = PI(); // 3.141592653589793
EULERSCONSTANT()
- Returns the mathematical constant e, which is the base of natural logarithms.
def real e = EULERSCONSTANT(); // 2.718281828459045
isEven(int value)
- Returns a boolean indicating whether the given integer is even
- You can use the
notvariant of this function as detailed here
def boolean value1 = isEven(34); // true
def boolean value2 = isEven(65); // false
def boolean value3 = (34).isEven(); // true
def boolean value4 = (65).isEven(); // false
isOdd(int value)
- Returns a boolean indicating whether the given integer is odd
- You can use the
notvariant of this function as detailed here
def boolean value1 = isOdd(34); // false
def boolean value2 = isOdd(65); // true
def boolean value3 = (34).isOdd(); // false
def boolean value4 = (65).isOdd(); // true
factorial(int value)
- Returns the factorial of the given integer
def int value1 = factorial(5); // 120
def int value2 = factorial(7); // 5040
def int value3 = (5).factorial(); // 120
def int value4 = (7).factorial(); // 5040
Make sure to give input in correct range or you might get an error
binomialCoefficient(int n, int k)
- Returns the binomial coefficient with the given inputs
def int value1 = binomialCoefficient(5, 2); // 10
def int value2 = binomialCoefficient(7, 3); // 35
def int value3 = (5).binomialCoefficient(2); // 10
def int value4 = (7).binomialCoefficient(3); // 35
Make sure to give input in correct range or you might get an error
combin(int n, int k)
- Returns the number of combinations for a given number of objects
def int value1 = combin(5, 2); // 10
def int value2 = combin(7, 3); // 35
def int value3 = (5).combin(2); // 10
def int value4 = (7).combin(3); // 35
Make sure to give input in correct range or you might get an error
combinA(int n, int k)
- Returns the number of combinations with repetitions for a given number of items
def int value1 = combinA(5, 2); // 15
def int value2 = combinA(7, 3); // 84
def int value3 = (5).combinA(2); // 15
def int value4 = (7).combinA(3); // 84
Make sure to give input in correct range or you might get an error
permutation(int n, int k)
- Returns the number of ways to choose some number of objects from a pool of a given size of objects, considering order.
def int value1 = permutation(5, 2); // 20
def int value2 = permutation(7, 3); // 210
def int value3 = (5).permutation(2); // 20
def int value4 = (7).permutation(3); // 210
Make sure to give input in correct range or you might get an error
permutationA(int n, int k)
- Returns the number of permutations for selecting a group of objects (with replacement) from a total number of objects
def int value1 = permutationA(5, 2); // 25
def int value2 = permutationA(7, 3); // 343
def int value3 = (5).permutationA(2); // 25
def int value4 = (7).permutationA(3); // 343
Make sure to give input in correct range or you might get an error
toRadians(numeric value)
- Converts the given value from degrees to radians
def real value1 = toRadians(180); // 3.141592653589793
def real value2 = toRadians(45); // 0.7853981633974483
def real value3 = (180).toRadians(); // 3.141592653589793
def real value4 = (45).toRadians(); // 0.7853981633974483
toDegrees(numeric value)
- Converts the given value from radians to degrees
def real value1 = toDegrees(2 * PI()); // 360.0
def real value2 = toDegrees(PI() / 2); // 90.0
def real value3 = (2 * PI()).toDegrees(); // 360.0
def real value4 = (PI() / 2).toDegrees(); // 90.0
logWithBase(numeric value, numeric base)
- Returns the logarithm of a value with the given base
def real value1 = logWithBase(25, 5); // 2.0
def real value2 = logWithBase(1.414, 2); // 0.4997821201473117
def real value3 = (25).logWithBase(5); // 2.0
def real value4 = (1.414).logWithBase(2); // 0.4997821201473117
log10(numeric value)
- Returns the logarithm of a value with base 10
def real value1 = log10(100); // 2.0
def real value2 = log10(71.45); // 1.854002233126989
def real value3 = (100).log10(); // 2.0
def real value4 = (71.45).log10(); // 1.854002233126989
ln(numeric value)
- Returns the logarithm of a value with base e (Euler's number)
def real value1 = ln(7.29); // 1.986503546020567
def real value2 = ln(12); // 2.4849066497880004
def real value3 = (7.29).ln(); // 1.986503546020567
def real value4 = (12).ln(); // 2.4849066497880004
exp(numeric value)
- Returns e (Euler's number) raised to the power of a given number
def real value1 = exp(2); // 7.38905609893065
def real value2 = exp(-1.32); // 0.26713530196585034
def real value3 = (2).exp(); // 7.38905609893065
def real value4 = (-1.32).exp(); // 0.26713530196585034
pow(numeric base, numeric exponent)
- Returns the result of base raised to exponent.
def int value1 = pow(7, 3); // 343
def real value2 = pow(12.12, 2.31); // 318.33988262150285
def real value3 = (7).pow(3); // 343
def real value4 = (12.12).pow(2.31); // 318.33988262150285
sqrt(numeric value)
- Returns the square root of a number.
def real value1 = sqrt(25); // 5.0
def real value2 = sqrt(7.29); // 2.7
def real value3 = (25).sqrt(); // 5.0
def real value4 = (7.29).sqrt(); // 2.7
Make sure to give input in correct range or you might get an error
cbrt(numeric value)
- Returns the cube root of a number.
def real value1 = cbrt(125); // 5.0
def real value2 = cbrt(0.729); // 0.9
def real number = 125;
def real value3 = number.cbrt(); // 5.0
getPrecision(numeric value)
- Returns the precision of a number.
def int value1 = getPrecision(125); // 3
def int value2 = getPrecision(0.729); // 4
def real number = 125;
def int value3 = number.getPrecision(); // 3
abs(numeric value)
- Returns the absolute value of a number.
def real value1 = abs(-25); // 25
def real value2 = abs(12.34); // 12.34
def real value3 = (-25).abs(); // 25
def real value4 = (12.34).abs(); // 12.34
ceil(numeric value)
- Get the ceiling of a number. Closest integer that is greater than or equal to the argument
def int value1 = ceil(-25.6); // -25
def int value2 = ceil(12.34); // 13
def int value3 = (-25.6).ceil(); // -25
def int value4 = (12.34).ceil(); // 13
floor(numeric value)
- Get the floor of a number. Closest integer that is less than or equal to the argument
def int value1 = floor(-25.6); // -26
def int value2 = floor(12.34); // 12
def int value3 = (-25.6).floor(); // -26
def int value4 = (12.34).floor(); // 12
sign(numeric value)
- Returns the signum of the number (1 if greater than 0, -1 if less than 0 and 0 if equal to 0)
def int value1 = sign(-25.6); // -1
def int value2 = sign(12.34); // 1
def int value3 = sign(0); // 0
def int value4 = (-25.6).sign(); // -1
def int value5 = (12.34).sign(); // 1
def int value6 = (0).sign(); // 0
round(numeric value, int places)
- Rounds a number to the specified number of places using Half-up methodology
def real value1 = round(-25.634, 2); // -25.63
def real value2 = round(12.34, 1); // 12.3
def real value3 = (-25.634).round(2); // -25.63
def real value4 = (12.34).round(1); // 12.3
roundUp(numeric value, int places)
- Rounds a number up to the specified number of places
def real value1 = roundUp(-25.634, 2); // -25.64
def real value2 = roundUp(12.34, 1); // 12.4
def real value3 = (-25.634).roundUp(2); // -25.64
def real value4 = (12.34).roundUp(1); // 12.4
roundDown(numeric value, int places)
- Rounds a number down to the specified number of places
def real value1 = roundDown(-25.634, 2); // -25.63
def real value2 = roundDown(12.34, 1); // 12.3
def real value3 = (-25.634).roundDown(2); // -25.63
def real value4 = (12.34).roundDown(1); // 12.3
roundTo(numeric value, int factor)
- Rounds a number to the nearest integer multiple of another
def real value1 = roundTo(-25.634, 7); // -28.0
def real value2 = roundTo(12.34, 3); // 12.0
def real value3 = (-25.634).roundTo(7); // -28.0
def real value4 = (12.34).roundTo(3); // 12.0
roundToOdd(numeric value)
- Rounds a number to the nearest odd number
def int value1 = roundToOdd(-25.634); // -25
def int value2 = roundToOdd(12.34); // 13
def int value3 = (-25.634).roundToOdd(); // -25
def int value4 = (12.34).roundToOdd(); // 13
roundToEven(numeric value)
- Rounds a number to the nearest even number
def int value1 = roundToEven(-25.634); // -26
def int value2 = roundToEven(12.34); // 12
def int value3 = (-25.634).roundToEven(); // -26
def int value4 = (12.34).roundToEven(); // 12
random()
- Get a real random number from 0 (inclusive) to 1 (exclusive)
def real value1 = random(); // 0.3423
def real value2 = random(); // 0.7893
def real value3 = random(); // 0.1234
def real value4 = random(); // 0.5678
randomInt(int min, int max)
- Get a int random number from min (inclusive) to max (exclusive)
def int value1 = randomInt(1, 10); // 7
def int value2 = randomInt(1, 10); // 3
def int value3 = randomInt(1, 10); // 5
def int value4 = randomInt(1, 10); // 2
randomReal(real min, real max, (Optional) int precision)
- Get a real random number from min (inclusive) to max (exclusive)
- You can pass an optional
precisionparamater to dictate the number of digits after decimal
def real value1 = randomReal(1.0, 10.0); // 3.242323
def real value2 = randomReal(1.0, 10.0, 2); // 3.24
def real value3 = randomReal(1.0, 10.0, 3); // 3.242
sin(numeric value)
- Returns the trigonometric sine of the given angle ( in radians )
def real value1 = sin(PI() / 4); // 0.7071067811865475
def real value2 = (PI() / 4).sin(); // 0.7071067811865475
cos(numeric value)
- Returns the trigonometric tangent of the given angle ( in radians)
def real value1 = cos(PI() / 4); // 0.7071067811865476
def real value2 = (PI() / 4).cos(); // 0.7071067811865476
tan(numeric value)
- Returns the trigonometric secant of the given angle ( in radians )
def real value1 = tan(PI() / 4); // 0.9999999999999999
def real value2 = (PI() / 4).tan(); // 0.9999999999999999
cosec(numeric value)
- Returns the trigonometric cosecant of the given angle ( in radians )
def real value1 = cosec(PI() / 4); // 1.4142135623730951
def real value2 = (PI() / 4).cosec(); // 1.4142135623730951
sec(numeric value)
- Returns the trigonometric cosecant of the given angle ( in radians )
def real value1 = sec(PI() / 4); // 1.414213562373095
def real value2 = (PI() / 4).sec(); // 1.414213562373095
cot(numeric value)
- Returns the trigonometric cotangent of the given angle ( in radians)
def real value1 = cot(PI() / 4); // 1.0000000000000002
def real value2 = (PI() / 4).cot(); // 1.0000000000000002
sinh(numeric value)
- Returns the hyperbolic sine of the given angle ( in radians )
def real value1 = sinh(PI() / 4); // 0.8686709614860095
def real value2 = (PI() / 4).sinh(); // 0.8686709614860095
cosh(numeric value)
- Returns the hyperbolic cosine of the given angle ( in radians )
def real value1 = cosh(PI() / 4); // 1.3246090892520057
def real value2 = (PI() / 4).cosh(); // 1.3246090892520057
tanh(numeric value)
- Returns the hyperbolic tangent of the given angle ( in radians)
def real value1 = tanh(PI() / 4); // 0.6557942026326724
def real value2 = (PI() / 4).tanh(); // 0.6557942026326724
cosech(numeric value)
- Returns the hyperbolic cosecant of the given angle ( in radians )
def real value1 = cosech(PI() / 4); // 1.1511838709208488
def real value2 = (PI() / 4).cosech(); // 1.1511838709208488
sech(numeric value)
- Returns the hyperbolic secant of the given angle ( in radians )
def real value1 = sech(PI() / 4); // 0.7549397087141313
def real value2 = (PI() / 4).sech(); // 0.7549397087141313
coth(numeric value)
- Returns the hyperbolic cotangent of the given angle ( in radians)
def real value1 = coth(PI() / 4); // 1.5248686188220641
def real value2 = (PI() / 4).coth(); // 1.5248686188220641
asin(numeric value)
- Returns the angle of the given trigonometric sine ( in radians)
def real value1 = asin(0.8731); // 1.0615250049325262
def real value2 = (0.8731).asin(); // 1.0615250049325262
acos(numeric value)
- Returns the angle of the given trigonometric cosine ( in radians)
def real value1 = acos(0.8731); // 0.5092713218623703
def real value2 = (0.8731).acos(); // 0.5092713218623703
atan(numeric value)
- Returns the angle of the given trigonometric tangent ( in radians)
def real value1 = atan(0.8731); // 0.7177528796345417
def real value2 = (0.8731).atan(); // 0.7177528796345417
atan2(numeric a, numeric b)
- Returns the angle of the given trigonometric tangent as a / b ( in radians)
def real value1 = atan2(1.23, 1.45); // 0.7034922613315149
def real value2 = (1.23).atan2(1.45); // 0.7034922613315149
acosec(numeric value)
- Returns the angle of the given trigonometric cosecant ( in radians)
def real value1 = acosec(2.34); // 0.44156007581723794
def real value2 = (2.34).acosec(); // 0.44156007581723794
asec(numeric value)
- Returns the angle of the given trigonometric secant ( in radians)
def real value1 = asec(2.34); // 1.1292362509776588
def real value2 = (2.34).asec(); // 1.1292362509776588
acot(numeric value)
- Returns the angle of the given trigonometric cotangent ( in radians)
def real value1 = acot(0.8731); // 0.853043447160355
def real value2 = (0.8731).acot(); // 0.853043447160355
acot2(numeric a, numeric b)
- Returns the angle of the given trigonometric cotangent as a / b ( in radians)
def real value1 = acot2(1.23, 1.45); // 0.8673040654633818
def real value2 = (1.23).acot2(1.45); // 0.8673040654633818
asinh(numeric value)
- Returns the angle of the given hyperbolic sine ( in radians)
def real value1 = asinh(0.8731); // 0.7887381563562876
def real value2 = (0.8731).asinh(); // 0.7887381563562876
acosh(numeric value)
- Returns the angle of the given hyperbolic cosine ( in radians)
def real value1 = acosh(1.8731); // 1.2403796463521428
def real value2 = (1.8731).acosh(); // 1.2403796463521428
atanh(numeric value)
- Returns the angle of the given hyperbolic tangent ( in radians)
def real value1 = atanh(0.8731); // 1.3459753582907523
def real value2 = (0.8731).atanh(); // 1.3459753582907523
acosech(numeric value)
- Returns the angle of the given hyperbolic cosecant ( in radians)
def real value1 = acosech(0.8731); // 0.9805075762885873
def real value2 = (0.8731).acosech(); // 0.9805075762885873
asech(numeric value)
- Returns the angle of the given hyperbolic secant ( in radians)
def real value1 = asech(0.8731); // 0.5328297158453046
def real value2 = (0.8731).asech(); // 0.5328297158453046
acoth(numeric value)
- Returns the hyperbolic cotangent of the given angle ( in radians)
def real value1 = acoth(1.8731); // 0.5955483841894608
def real value2 = (1.8731).acoth(); // 0.5955483841894608
lcm(int a, int b)
- Returns the least common multiple of a and b
def int value1 = lcm(12, 8); // 24
def int value2 = (12).lcm(8); // 24
gcd(int a, int b)
- Returns the greatest common divisor of a and b
def int value1 = gcd(12, 8); // 4
def int value2 = (12).gcd(8); // 4
toDateFromEpochDays(int value)
- Creates Date from epoch days (days since Jan 1, 1970)
def Date value1 = toDateFromEpochDays(10000); // 1997-05-19
def Date value2 = (10000).toDateFromEpochDays(); // 1997-05-19
toDateTimeFromEpochDays(int value)
- Creates DateTime from epoch days (days since Jan 1, 1970)
def DateTime value1 = toDateTimeFromEpochDays(10000); // 1997-05-19T00:00
def DateTime value2 = (10000).toDateTimeFromEpochDays(); // 1997-05-19T00:00
toDateFromEpochSeconds(int value)
- Creates Date from epoch seconds (seconds since Jan 1, 1970)
def Date value1 = toDateFromEpochSeconds(1000000000); // 2001-09-09
def Date value2 = (1000000000).toDateFromEpochSeconds(); // 2001-09-09
toDateTimeFromEpochSeconds(int value)
- Creates DateTime from epoch seconds (seconds since Jan 1, 1970)
def DateTime value1 = toDateTimeFromEpochSeconds(1000000000); // 2001-09-09T01:46:40
def DateTime value2 = (1000000000).toDateTimeFromEpochSeconds(); // 2001-09-09T01:46:40
toTimeFromSeconds(int value)
- Creates Time from seconds (seconds since the beginning of the day)
def Time value1 = toTimeFromSeconds(8457); // 02:20:56
def Time value2 = (8457).toTimeFromSeconds(); // 02:20:56
min(numerics... values)
- Calculates the minimum number from the given numbers (At least one needs to be provided)
def real value1 = min(12.344,4554.224,-12,-782.24); // -782.24
def real value2 = min(35, 45, 23.35, 12, 34); // 12
max(numeric... values)
- Calculates the maximum number from the given numbers (At least one needs to be provided)
def real value1 = max(12.344,4554.224,-12,-782.24); // 4554.224
def real value2 = max(35, 45, 23.35, 12, 34); // 45
average(numeric... values)
- Calculates the average of the given numbers (At least one needs to be provided)
def real value1 = average(12.344,4554.224,-12,-782.24); // 943.082
def real value2 = average(35, 45, 23.35, 12, 34); // 28.6
sum(numeric... values)
- Calculates the sum of the given numbers (At least one needs to be provided)
def real value1 = sum(12.344,4554.224,-12,-782.24); // 3772.328
def real value2 = sum(35, 45, 23.35, 12, 34); // 150.35
geometricMean(numeric... values)
- Calculates the geometric mean number of the given numbers (At least one needs to be provided)
def real value1 = geometricMean(12.344,4554.224,-12,-782.24); // 151.56464
def real value2 = geometricMean(35, 45, 23.35, 12, 34); // 28.6
harmonicMean(numeric... values)
- Calculates the harmonic mean of the given numbers (At least one needs to be provided)
def real value1 = harmonicMean(12.344,4554.224,-12,-782.24); // -1183.040115747569
def real value2 = harmonicMean(35, 45, 23.35, 12, 34); // 18.0
median(numeric... values)
- Calculates the median of the given numbers (At least one needs to be provided)
def real value1 = median(12.344,4554.224,-12,-782.24); // -12.0
def real value2 = median(35, 45, 23.35, 12, 34); // 34.0
mode(numeric... values)
- Calculates the mode of the given numbers (At least one needs to be provided)
def real value1 = mode(12.344,4554.224,12.344,-782.24); // 12.344
def real value2 = mode(35, 45, 23.35, 12, 34); // 34.0
formatInt(int value, string thousandsSeparatorString)
- Converts a integer value to string with the given single width string to separate thousands
def int number = 12345678;
def string value1 = formatInt(number, ","); // 12,345,678
def string value2 = formatInt(number, ","); // 12_345_678
def string value3 = number.formatInt(","); // 12,345,678
def string value4 = number.formatInt(","); // 12_345_678
If thousandsSeparatorString is passed, make sure that it is a single width string. Otherwise, an error will be thrown
formatReal(real value, int precision, (optional) string decimalSeparator, (optional) string thousandsSeparatorString)
- Converts a floating point value to string with the given precision
- You can optionally provide
decimalSeparatorandthousandsSeparatorStringfor formatting
def real number = 12345678.345;
def string value1 = formatReal(number, 2); // 12345678.34
def string value2 = number.formatReal(4); // 12345678.3450
def string value3 = formatReal(number, 2, ","); // 12345678,34
def string value4 = number.formatReal(4, ",", "_"); // 12_345_678,3450
If decimalSeparator or/and thousandsSeparatorString is passed, make sure that it is a single width string. Otherwise, an error will be thrown
formatCurrency(real amount, string currency, string locale, string format)
- Formats amount in the given
currency,localeandformat
def real amount = 231.2355;
def string result1 = formatCurrency(amount,"USD", "en_US", "C##,###.##"); // $231.24
def string result2 = amount.formatCurrency("USD", "en_US", "C##,###.##"); // $231.24