The floor(x)
method will return the nearest integral value of x that is less than or equal to x.
floor(x)
x
: The value for which the floor value is to be calculated.
The nearest integral less than or equal to the specified value will be returned.
The code below demonstrates how to use the floor
method.
## find floor of 3 println( "floor(3) => $(floor(3))") ## find floor of 3.4 println( "floor(3.4) => $(floor(3.4))") ## find floor of 3.6 println( "floor(3.6) => $(floor(3.6))") ## find floor of 3.99 println( "floor(3.99) => $(floor(3.99))")
In the above code, we do the following:
Line 2: We use the floor
method with 3
as an argument. The floor(3)
will return 3
.
Line 5: We use the floor
method with 3.4
as an argument. The floor(3.4)
will return 3.0
.
Line 8: We use the floor
method with 3.6
as an argument. The floor(3.6)
will return 3.0
.
Line 11: We use the floor
method with 3.99
as an argument. The floor(3.99)
will return 3.0
.
RELATED TAGS
CONTRIBUTOR
View all Courses