ceil()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Oct 26, 2023
Contribute to Docs

The ceil() method in Kotlin’s math library rounds a floating-point number up to the nearest integer.

Syntax

kotlin.math.ceil(x)
  • x: A value of type Double or Float to be rounded up.

Example

The following code demonstrates a basic implementation of the ceil() method.

val myDouble: Double = 7.5
val myFloat: Float = 6.3f
val myInt: Int = 4
val resultDouble: Double = ceil(myDouble)
val resultFloat: Float = ceil(myFloat)
val resultInt: Double = ceil(myInt.toDouble())
fun main() {
println(resultDouble)
println(resultFloat)
println(resultInt)
}

This will return the following output:

8.0
7.0
4.0

All contributors

Contribute to Docs

Learn Kotlin on Codecademy