🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators toInteger () : Integer
This page was created by Stephanie on 2023-04-12. Last edited by Wikiadmin on 2026-07-29.

You can use toInteger() when an OCL value must be interpreted as an Integer; it is for OCL expressions that need an integer result from a value representing an integer.

Syntax

self.toInteger()

Return value

toInteger() returns an Integer with the same value as self when self represents an integer. If self does not represent an integer, the result is |invalid|.

Value represented by self Result
An integer value, such as 42 The Integer 42
A value that does not represent an integer invalid|

Use it for integer conversion

Use toInteger() when the input is expected to represent a whole-number value and your expression requires an Integer. Check or handle the possibility of |invalid| when the source value can contain non-integer content.

Do not use this operation to remove a fractional part or choose the nearest whole number. Use Number::floor() to return the integer part of a Real, or Number::round() to return the nearest integer.

Related integer operations

After you have an Integer, use Integer::div() for an integer quotient and Integer::mod() for an integer remainder. For the infix form and general behavior of integer division, see div.

See also