OCLOperators Number::floor () : Integer
This page was created by Peter on 2019-11-25. Last edited by Wikiadmin on 2026-07-29.
You can use floor() in OCL expressions when you need an Integer from a numeric value by taking the integer part of a Real value.
Syntax
number.floor()Return value
floor() is a Number operation with the following signature:
Number::floor() : IntegerIt returns:
- The integer part of
selfwhenselfis a Real. selfunchanged whenselfis an Integer.
Examples
The following expression applies floor() to a Real value:
3.7.floor()The result is 3.
When the input is already an Integer, the operation returns that Integer:
12.floor()The result is 12.
Choose the appropriate numeric operation
| Requirement | Operation to use |
|---|---|
| Get the integer part of a Number | floor()
|
| Get the nearest integer | round()
|
Convert a value only when it represents an integer; otherwise receive invalid
|
toInteger()
|
| Get the integer quotient when dividing two Integers | div
|
For example, use floor() when you already have a numeric value and need its integer part. Use div when your intent is integer division, because div calculates the quotient of two values rather than operating on one value.
