Extract and Format Numbers

Prev Next

These functions provide tools that interpret numeric values. Many of these functions return information as an integer, which can be further evaluated with mathematical operations.

Modifications to the extracted values are made for the purposes of the query only. The actual data stored in the target source is not changed in any way.

Function Overview

Function

Description

​ecx:formatNumber​

Formats a number based on the specified variables.

ecx:forceNumber

Parses numbers in a string attribute as an actual number. This function works in tandem with exc:formatNumber.

​ecm:round​

Rounds the target number up to a value determined by the specified number of fractional digits.

​Mathematical Operations (General)​

A full range of mathematical operations can be used in association with functions.

​ecm:max​

Returns the maximum value from the specified arguments.

​ecm:min​

Returns the minimum value from the specified arguments.

​ecm:avg​

Returns the average value from the specified arguments.

​ecm:random​

Returns a random positive integer between two integers.

ecx:distribute

Generates a random result according to the standard uniform distribution.


​ecx:formatNumber​

The function ecx:formatNumber formats a number based on the specified variables. The value returned is a string data type.

Examples

Function

Returns

<%${ecx:formatNumber('1123.45', '', 'fr')}%>

1 123,45

<%${ecx:formatNumber('67890', '', 'aus')}%>

67,890

<%${ecx:formatNumber('11223344.55', '', 'aus')}%>

11,223,344.55

<%${ecx:formatNumber('100', '$#', '')}%>

$100

<%${ecx:formatNumber('50', '# €', '')}%>

50 €

<%${ecx:formatNumber('0.56', '#%', '')}%>

56%

<%${ecx:formatNumber('test', '#%', '')}%>

test

<%${ecx:formatNumber('100.01', '#,##0.00', '')}%>

100,01

Structure​

ecx:formatNumber(string1, string2, string3)

Parameters​

Parameter

Description

string1

The target value to format. If the target string is not a number, the string is returned unmodified.

string2

Symbol added before or after the number. Any character entered in this parameter is appended to the number based on its placement relative to the number sign (#), which represents the number itself.

string3

Variable localeCode. Applies a country-specific format to the number based on the ISO language code used. This parameter determines the characters used to separate thousands and decimal values.


ecx:forceNumber

The function ecx:forceNumber parses numbers in a string attribute as an actual number. This function works in tandem with exc:formatNumber.

Function Logic​

  • If string_or_number is null:
    > return 0

  • else if string_or_number is numeric:
    > return string_or_number

  • else if string_or_number is convertible to numeric after replacing any , to . to ensure compatibility with different decimal separators:
    > return numeric converted value with . as decimal separator

  • else if:
    > return 1

  • end if

Examples

Function

Returns

<%${ecx:forceNumber(' ')}%>

0

<%${ecx:forceNumber('124.66')}%>

124.66

<%${ecx:forceNumber('124,66')}%>

124.66

<%${ecx:forceNumber('text')}%>

1

Structure​

ecx:formatNumber(ecx:forceNumber("user.AttributeType.StringAttribute"))


​ecm:round​

The function ecm:round rounds the target number up to a value determined by the specified number of fractional digits. The value returned is an integer data type.

Example

An external application regularly updates the prices of items in a product catalog. The application calculates currency conversions to values with four decimal places. These values are imported into an unlinked related data set named ​Products.

Prices from this data set are inserted into a message, rounding the number to two decimal places. The expression is constructed as follows:

<%${ecm:round((ecx:related('Products',user.CustomAttribute['ProductID_2'])['Price'],2)}%>

Structure​

ecm:round(number, integer)

Parameters​

Parameter

Description

number

Specifies the target value to be rounded.

integer

Specifies the number of fractional digits to be included in the result.


​Mathematical Operations (General)​

A full range of mathematical operations can be used in association with functions. Mathematical operations return numbers as results. If any non-numeric values are subjected to mathematical operations (for example, a string), the non-numeric value is returned unmodified. Calculations that contain more than one arithmetic operation use the standard order of operations. For example, the calculation ${10+15*3-5} returns a value of 50.

Example

The custom attribute (​AtbNumber​) is assigned a numeric data type.

When the value stored in ​AtbNumber​ is ​5​, the following function returns a numeric value of ​15​:

<%${user.CustomAttribute['AtbNumber']*4-5}%>

​ecm:max​

The function ecm:max returns the maximum value from the specified arguments. Only arguments with numeric data types are evaluated. Null arguments or non-number data types are ignored. The value returned is an object type.

Example

${ecm:max(6,10,8)}

This returns 10.

Structure​

ecm:max(object...)

Parameters​

Parameter

Description

object

Specifies a target object to evaluate. Additional objects are added as a list, separated by commas.


​ecm:min​

The function ecm:min returns the minimum value from the specified arguments. Only arguments with numeric data types are evaluated. Null arguments or non-number data types are ignored. The value returned is an object type.

Example

${ecm:min(6,10,8)}

This returns 6.

Structure​

ecm:min(object...)

Parameters​

Parameter

Description

object

Specifies a target object to evaluate. Additional objects are added as a list, separated by commas.


​ecm:avg​

The function ecm:avg returns the average value from the specified arguments. Only arguments with numeric data types are evaluated. Null arguments or non-number data types are ignored. The value returned is an object type.

Example

${ecm:avg(6,10,8)}
This returns 8.

Structure​

ecm:avg(object...)

Parameters​

Parameter

Description

object

Specifies a target object to evaluate. Additional objects are added as a list, separated by commas.


​ecm:random​

The function ecm:random returns a random positive integer between two integers. The result can include the values used to define the upper and lower ranges. The value returned is an integer data type.

${ecm:random(3, 6)}

This returns an integer value from the range 3 to 6, for example, 5.

Structure​

ecm:random(integer, integer)

Parameters​

Parameter

Description

integer

Specifies the lower range of the result.

integer

Specifies the upper range of the result.

If either parameter is entered as a negative integer or the lower range value is greater than the upper range, the function returns a value of -1


ecx:distribute

The function ecx:distribute generates a random result according to the standard uniform distribution. The parameters define the ratio of the probability that the result returns the value true. The value returned is a Boolean data type.

Example

A message contains a personalized message which includes a special offer. The offer is only visible to a percentage of randomly selected recipients.

The expression that inserts personalization into a message is constructed as follows:

<%InsertIf expression="${ecx:distribute(1,5)}" id="name"%>Text1<%/InsertIf%>

In this example, there is a 20% (1 in 5) chance that personalization is displayed in the message.

The ID assigned to the personalization identifies the variation in the statistics and helps measure the performance of messages sent with the personalized message part.

The ID assigned to the personalization in the expression is limited to 35 characters.

Structure​

ecx:distribute(integer, integer)

Parameters​

Parameter

Description

integer

Specifies a percentage of the total distribution.

integer

Specifies the total number considered for the distribution.