Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala

What is the ceil() 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 ceil() method in Scala gets an integer that is greater than or equal to a given number by rounding up the given number.

Syntax

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

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

Return value

The ceil() method returns the ceil value of a number by rounding up the number.

Example

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

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

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