SYNTAX

<Decimal>.toInteger

<String>.toInteger

DESCRIPTION

Converts the value in <Decimal> or all characters in <String> to data type Integer. All decimals have fractional portions truncated during the conversion. Strings are converted ONLY if all characters in <String> are numeric, without a decimal point. If any non-numeric characters (with the sole exception of a single leading minus sign for negative numbers) are present in <String>, no value is returned by the function. Do not use on String values of null or empty String ( '' ) -- a pair of single quote marks -- as that will generate an error message.

USAGE RESTRICTIONS

The Operators row of the table in Summary Table of Vocabulary Usage Restriction applies. No special exceptions.

RULESHEET EXAMPLE

The following Rulesheet uses .toInteger to convert decimal1 and string1 to type Integer and assign them to integer1 and integer2, respectively.

SAMPLE TEST

Cases when the toInteger operator accepts null and empty values for string attributes

There are two factors:
  1. Prior to evaluating a rule, Corticon checks if any attribute values used in the expressions in the rule are null and, if so, does not execute the rule.
  2. During expression evaluation, Corticon protects against null pointer exceptions. The expression "test.string.toInteger" will return null if the string is not an integer. However, the expression "test.string.toInteger + 3" will return “3” if the string is not a number – the value 0 being used as the result of the toInteger.
Consider the action expression:
test.integer =test.string.toInteger
Here is the Ruletest output for three tests:
How this Ruletest was processed:
  • In test 1, the string is empty but not a null value so the expression evaluates and assigns null to integer.
  • In test 2, the string is null so the pre-check for null values does not pass and the expression is not evaluated and the value of integer is unchanged
  • In test 3, the string is the string “null” but not a null value so the expression evaluates and assigns null to integer. (Note the value “null” here is a string, it could have just as well been “foo”).
Now change the action expression to:
test.integer =test.string.toInteger + 3
Here is the Ruletest output now:
How this Ruletest was processed now:
  • In test 1, the string is empty but not a null value so the expression evaluates. To prevent a NPE during evaluation, the value 0 is used as the result of the toInteger resulting in the expression being “0 + 3” so integer is assigned a value of 3.
  • In test 2, the string is null so the pre-check for null values does not pass and the expression is not evaluated and the value of integer is unchanged.
  • In test 3, the string is the string “null” but not a null value so the expression evaluates in the same fashion as 1, that is, “0 + 3” and assigns a value of 3.
You might argue that you cannot assume a value of 0 when doing toString on a non-number string. However, to protect a business user against runtime exceptions, Corticon makes logical substitutions during rule evaluation to protect against null values.