Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala

What is the floor() method in Scala?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The floor() method in Scala gets an integer that is less than or equal to a given number by rounding down the given number.

Syntax

The floor() method can be declared as shown in the code snippet below:

(num).floor
  • num: The number whose floor value is required.

Return value

The floor() method returns the floor value of a number by rounding down the number.

Example

The code snippet below demonstrates the use of the floor() method:

object main {
def main(args: Array[String]) = {
val n1 = -2.5;
println("(-2.5).floor: " + (n1).floor);
val n2 = -2.2;
println("(-2.2).floor: " + (n2).floor);
val n3 = 0;
println("(0).floor: " + (n3).floor);
val n4 = 3.9;
println("(3.9).floor: " + (n4).floor);
val n5 = 3.1;
println("(3.1).floor: " + (n5).floor);
}
}

RELATED TAGS

scala

CONTRIBUTOR

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring