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 / divisorThe 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.
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 / ProjectCountFor 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.
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.
