Kotlin ceil()

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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
    • Beginner Friendly.
      9 hours

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
    • Beginner Friendly.
      9 hours