🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators divide
This page was created by Charles on 2025-11-18. Last edited by Wikiadmin on 2026-08-17.

You can use the / operator in OCL expressions to calculate a numeric quotient, for example an average in a derived attribute or constraint.

Syntax

dividend / divisor

The dividend is the numeric value being divided. The divisor is the numeric value to divide by.

For example, EmployeeCount / ProjectCount divides the number of employees by the number of projects.

Basic Syntax

a / b

a → dividend

Result

The divide operator is an arithmetic operator. Its result is typically of type Real, including when both operands are integers.

Expression Meaning
EmployeeCount / ProjectCount The number of employees divided by the number of projects.
12 / 3 A quotient of 4.

Example: average employees per project

Assume that the Department class has these attributes:

Attribute Type Meaning
EmployeeCount Integer Number of employees in the department.
ProjectCount Integer Number of projects in the department.

In an OCL expression evaluated in the context of a Department, calculate the average number of employees per project with:

EmployeeCount / ProjectCount

For a department with EmployeeCount = 12 and ProjectCount = 3, the expression returns 4. Because / typically returns a Real, use it when the result represents a ratio or average rather than an integer-only quotient.

Calculate Average Employees per Project

self.EmployeeCount / self.ProjectCount

Using Division with a Department Collection

You can also use division within a collection operation:

Department.allInstances
  ->collect(d | d.EmployeeCount / d.ProjectCount)

Returns the average employees per project for each department.

Choose the appropriate division operation

Use / when you need the normal numeric division result. If you need an integer quotient instead, use Integer::div.

Do not use the division operator when you need a remainder. Number::ieeereminder is a separate operation with IEEE remainder semantics.

See also