You can use parse in OCL expressions to convert text into a value such as an Integer or Decimal, and test whether the conversion succeeded.
Syntax
Call parse on the target value type and pass the text to convert:
Type.parse('text')
Most value types, including Integer and Decimal, provide this function.
Convert text to a number
Use Decimal.parse when the result must be a Decimal value.
Decimal.parse('10')
Use Integer.parse when the result must be an Integer value.
Integer.parse('5')
For example, if an expression receives the text '5', Integer.parse('5') produces the corresponding Integer value.
Handle invalid input
If the supplied text cannot be converted to the requested type, parse returns NULL. It does not produce a converted value.
Test the result with isNull when the input may be invalid:
Decimal.parse('x').isNull
This expression returns true because 'x' cannot be converted to a Decimal.
Use this pattern when converting user-entered or externally supplied text: parse the text first, then check whether the result is NULL before relying on the converted value.
Find available operators
To inspect the operators available for a type, open the OCL editor and type the class name. See OCL General Operators for guidance on finding operators.
