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

You can use round() in OCL expressions to convert a numeric value to its nearest Integer.

Syntax

number.round()

Result

Number::round() : Integer returns an Integer.

  • When self is a Real, it returns the Integer nearest to that value.
  • When self is already an Integer, it returns self unchanged.

Examples

Expression Result Explanation
3.6.round() 4 3.6 is nearest to 4.
3.2.round() 3 3.2 is nearest to 3.
(-3.6).round() -4 -3.6 is nearest to -4.
7.round() 7 The input is already an Integer.

Choose the appropriate numeric operation

Use round() when you need the nearest whole-number value. For example, use Order.Total.round() when an OCL expression must produce an Integer nearest to an order total.

Do not use round() when you need a different conversion rule:

  • Use floor() to return the integer part of a Real rather than the nearest Integer.
  • Use toInteger() when the value must already represent an integer; it returns invalid when it does not.
  • Use div or Integer::div() when you need the integer quotient of a division.
  • Use toDecimal when you need a decimal number for calculations rather than an Integer.

See also