🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Integer
This page was created by Stephanie on 2023-05-19. Last edited by Wikiadmin on 2026-07-29.

An Integer stores a whole-number value, such as a quantity, sequence number, or count, for MDriven developers who need attributes and calculations without decimal places.

Use Integer for whole-number values

Use an Integer attribute when a value must not contain a fractional part.

For example, in an order model you might use:

  • Quantity : Integer for the number of items ordered.
  • SortOrder : Integer for the position of an item in a list.
  • NumberOfSeats : Integer for a seat count.

Do not use an Integer when the value must retain a decimal part. A value such as 2.5 is not a whole number.

Integer values in OCL

In OCL, Integer values can be used in arithmetic and comparisons. For example, if Quantity is an Integer:

self.Quantity + 1
self.Quantity > 0
self.Quantity = 10

The first expression returns the next whole-number quantity. The second evaluates whether the quantity is positive. The third evaluates whether it is exactly 10.

Division and remainder

Use the Integer-specific operations div and mod when you need a quotient or remainder.

Expression Result Use
7 div 2 3 Returns the integer quotient. See Integer::div.
7 mod 2 1 Returns the remainder. In MDriven, mod is an infix operator. See Integer::mod.

For example, use self.SequenceNumber mod 2 = 0 to test whether a sequence number is even.

Convert values to Integer

When a number has a decimal part, use an OCL operation that states how to produce a whole-number result:

Situation Operation Example
Keep the integer part of a number Number::floor() 3.9.floor() returns 3.
Return the nearest integer Number::round() 3.6.round() returns 4.
Convert a value that represents an integer toInteger() or strToInt invalid|.

Check conversion input before relying on the result. For example, text that does not represent an integer produces |invalid| when converted with toInteger() or strToInt.

Int32

Int32 is a signed 32-bit Integer type. It stores values from -2,147,483,648 through 2,147,483,647. Use the Int32 page when you need the range and storage details for that type.

See also

[[Category:Attributes and data types [Beginner]]]