Calculated Attribute expressions can be written using the following available functions. Examples follow the Available Functions table.
Available Functions
|
Number Function |
Parameters |
Description |
|---|---|---|
|
TEXT |
(number, format string) |
Returns a textual representation of the supplied number, formatted by the supplied formatting string. |
|
TRUNC |
(number) |
Returns the integer part of ‘number’ by removing the decimal and any numbers following it. No rounding is performed. |
|
INT |
(number) |
Returns the integer part of ‘number’ by rounding down to the nearest integer. Negative numbers are rounded down. |
|
ROUND |
(number, precision) |
Returns ‘number’, rounded to a specified number of digits.
|
|
LOCALIZENUMBER |
(number[, locale]) |
Localizes the number to a string, using the locale in the current / extracting / resolving context, or using the supplied locale. [locale] is optional; see Using a Locale below |
|
Binary number functions |
+, -, *, / |
Returns the computed number of the operation. If possible, text is converted to a number. If number conversion fails, 'NaN' (meaning 'Not a Number') is returned. Note: Rounding errors can occur when using the binary number functions in number calculations. To correct rounding in these cases, use the ROUND or TEXT function. |
|
Binary logical functions |
<, >, <=, >=, =,!= |
Returns TRUE (=1) or FALSE (=0). Note: These functions do NOT work on text strings and always attempt to convert to a number. |
Using a Locale
When using calculations on numbers, use the LOCALIZENUMBER() and specify a locale ID that uses a 'dot-is-decimal' method (for example, 12.34) and not a 'comma-is-decimal' method (for example, 12,34). After the calculation, use the function again to convert the decimal point value to the required locale's format. Ensure the following property is defined in the sharedconfig.properties file: Calculated.UseLegacyLocalization=true
For more information on locales, see Context Locales documentation in this guide here.
Examples
Copy and paste any of the following examples into the Function Editor and then evaluate against the specified object to get the defined result.
text(2.45, '000.0') // = "002.5"text(2.45, '.0') // = "2.5"text(2000.45, ',.0') // = "2,000.5"trunc(5.64) // = 5int(5.64) // = 5int(-5.64) // = -6trunc(-5.64) // = -5round(5.64, 0) // = 6round(5.64, 1) // = 5.6round(5.64, -1) // = 101.25*11 // = 13.75
(value('AttID1'))*(value('AttID2')) // = the result of (attribute 1's value) multiplied by (attribute 2's value)In the example below, the Diameter attribute is in a context where a locale with a 'comma-is-decimal' method is used and has the value: 12,7
Evaluating the following value template shows that if you attempt to make a math calculation on a number that is using the comma-is-decimal method, the calculation does not work, as indicated by the NaN ('not a number') result. Instead, perform calculations in a 'dot-is-decimal' locale (en_US or en_GB, for example) and then convert back to the preferred locale after the calculation has been done. In this example, this is done by the statement 'num := localizenumber(p),' which reverts the calculated number to the format according to the locale that is specified in the currently selected context.
{x := value('Diameter'), y := 3.414,num_us := localizenumber(x, "en_US"), num_de := localizenumber(x, "de_DE"),
p := num_us*y, q := num_de*y,
num := localizenumber(p)}
concatenate(x, " ", p, " ", q, " ", num)
//12,7 43.3578 NaN 43,3578
2017, Stibo Systems