MEP Expression Language
Functions for Percentages, Numbers, PINs
The following functions are related to percentages, numbers and PINs.
Generate numbers or PINs
The following functions generate random numbers or PINs.
Function |
Description |
Output |
---|---|---|
random(integer) |
Returns a random integer between 0 (inclusive) and the specified integer (exclusive). For example, to generate a random integer with 100 as the highest possible number, use the expression ${af:random(101)}. |
Integer |
randomBetween (integer-low, integer-high)
|
Returns a random integer between the two specified integers. The integer-low number must be a lower numerical value than the integer-high number. The possible integers returned by the function includes the integer-low number but excludes the integer-high number. For example, to generate a random integer between (and including) 10 and 90, use the expression ${af:randomBetween(10,91)}. |
Integer |
generatePin(integer, Boolean) |
Generates a random PIN. The integer value specifies the length of the PIN, while the Boolean value (either true or false) determines whether the PIN is an alphanumeric string (true) or an integer (false). Example expressions and values:
|
Integer, String |
Round a number up or down
Function |
Description |
Output |
---|---|---|
toInt(number) |
Rounds a floating point number to the nearest integer. For example: ${af:toInt(3.87)} would return 4. |
Integer |
ceil(number)
|
Rounds a number up to the nearest integer, but returns this as a floating point number to one decimal point. For example: ${af:ceil(4.33)} would return 5.0. |
Floating-point number |
floor(number) |
Rounds a number down to the nearest integer, but returns this as a floating point number to one decimal point. For example: ${af:floor(7.9)} would return 7.0. |
Floating-point number |
round(number)
|
Rounds a number to the nearest integer, but returns this as a floating point number to one decimal point. For example: ${af:round(1.73)} would return 2.0. This function uses the "half up" rounding convention, so ${af:round(2.5)} would return 3.0. |
Floating-point number |
roundtoDP(number, decimal-place)
|
Rounds a number to the specified number of decimal places. You must specify the number of decimal places for the returned number with decimal-place. For example: ${af:roundtoDP(12.1115, 3)} would return 12.112. |
Floating-point number |
Retrieve phone numbers
Function |
Description |
Output |
---|---|---|
getPhoneNumber(input) |
The function reads the specified input and attempts to extract a UK MSISDN. The function will look for mobile numbers beginning with either the number zero or the UK international prefix (44, 0044, +44). It will output the first matching number. This function is commonly used to extract a number out of SMS message text, for example: ${af:getPhoneNumber(request.defaultMessage)} The output returned is in international format without a leading "+" character. For example, 447700900765. |
Integer |
getUSPhoneNumber (input) |
The function reads the specified input and attempts to extract a US phone number. It looks for 10 digit numbers beginning with or without the US international prefix (1, +1), and outputs the first matching number. This function is commonly used to extract a number out of SMS message text, for example: ${af:getUSPhoneNumber(session.initialMessage.strippedMessage)} The output returned is in international format without a leading "+" character. For example, 12515550130. |
Integer |
Ordinalize a number
Function |
Description |
Output |
---|---|---|
ordinal(integer) |
Returns the integer as an ordinal string; i.e. with a suffix of either "st", "nd" "rd" or "th". For example:
|
String |
Turn input into a percentage value
Function |
Description |
Output |
---|---|---|
calculatePercentage(integer-A,integer-B) |
This function calculates a percentage from two inputs. The function divides integer-A by integer-B, multiplies the value by 100, then rounds the value to the nearest integer. It appends the value with the percentage mark. For example, the expression: ${af:calculatePercentage(50,150)} would return the value 33%. |
String |
formatPercentage (number) |
Formats a floating point number or an integer as a percentage. It assumes that the number has already been calculated as a percentage. The number is also rounded to the nearest integer. For example: ${af:formatPercentage(14.87)} would return 15%. |
String |
Compares integers
Function |
Description |
Output |
---|---|---|
max(integer-A, integer-B) |
Returns the larger of the two integers. For example: ${af:max(25,85)} would return 85. |
Integer |
min(integer-A, integer-B) |
Returns the smaller of the two integers. For example: ${af:max(12,49)} would return 12. |
Integer |