The ceil()
method in Scala gets an integer that is greater than or equal to a given number by rounding up the given number.
The ceil()
method can be declared as shown in the code snippet below:
(num).ceil
num
: The number whose ceil value is required.The ceil()
method returns the ceil value of a number by rounding up the number.
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);}}