ceil()
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 typeDouble
orFloat
to be rounded up.
Example
The following code demonstrates a basic implementation of the ceil()
method.
val myDouble: Double = 7.5val myFloat: Float = 6.3fval myInt: Int = 4val 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.07.04.0
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours