Kotlin Math.ceil - Syntax
mixed ceil(mixed n)
The Math.ceil() function in Kotlin is used to return the next highest integer value by rounding up value if necessary.
mixed ceil(mixed n)
mixed n |
Specifies the real number (int, long, float, double) / infinity (*Required) |
---|---|
Return mixed |
Returns a number / infinity respective to an input argument. |
Round the floating point number from 1.0 to 2.0 step by 0.1 using ceiling math method and print the resultant in console.
fun main(args: Array) {
println("The ceiling value of 1.0 is " + Math.ceil(1.0))
println("The ceiling value of 1.1 is " + Math.ceil(1.1))
println("The ceiling value of 1.2 is " + Math.ceil(1.2))
println("The ceiling value of 1.3 is " + Math.ceil(1.3))
println("The ceiling value of 1.4 is " + Math.ceil(1.4))
println("The ceiling value of 1.5 is " + Math.ceil(1.5))
println("The ceiling value of 1.6 is " + Math.ceil(1.6))
println("The ceiling value of 1.7 is " + Math.ceil(1.7))
println("The ceiling value of 1.8 is " + Math.ceil(1.8))
println("The ceiling value of 1.9 is " + Math.ceil(1.9))
println("The ceiling value of 2.0 is " + Math.ceil(2.0))
}
Round the positive floating point number (random numbers) using ceiling math method and print the resultant in console.
fun main(args: Array) {
println("The ceiling value of 1.5698 is " + Math.ceil(1.5698))
println("The ceiling value of 1.3093 is " + Math.ceil(1.3093))
println("The ceiling value of 1.0087 is " + Math.ceil(1.0087))
println("The ceiling value of 1.1038 is " + Math.ceil(1.1038))
println("The ceiling value of 1.9573 is " + Math.ceil(1.9573))
println("The ceiling value of 1.7462 is " + Math.ceil(1.7462))
println("The ceiling value of 1.6427 is " + Math.ceil(1.6427))
println("The ceiling value of 1.4128 is " + Math.ceil(1.4128))
println("The ceiling value of 1.8099 is " + Math.ceil(1.8099))
println("The ceiling value of 1.2743 is " + Math.ceil(1.2743))
println("The ceiling value of 2.0001 is " + Math.ceil(2.0001))
}
Round the negative floating point number (random numbers) using ceiling math method and print the resultant in console.
fun main(args: Array) {
println("The ceiling value of -1.5698 is " + Math.ceil(-1.5698))
println("The ceiling value of -1.3093 is " + Math.ceil(-1.3093))
println("The ceiling value of -1.0087 is " + Math.ceil(-1.0087))
println("The ceiling value of -1.1038 is " + Math.ceil(-1.1038))
println("The ceiling value of -1.9573 is " + Math.ceil(-1.9573))
println("The ceiling value of -1.7462 is " + Math.ceil(-1.7462))
println("The ceiling value of -1.6427 is " + Math.ceil(-1.6427))
println("The ceiling value of -1.4128 is " + Math.ceil(-1.4128))
println("The ceiling value of -1.8099 is " + Math.ceil(-1.8099))
println("The ceiling value of -1.2743 is " + Math.ceil(-1.2743))
println("The ceiling value of -2.0001 is " + Math.ceil(-2.0001))
}
Round the infinity using ceiling math method and print the resultant in console.
import kotlin.Double.Companion
fun main(args: Array) {
// Positive ∞ infinite value
println("The ceiling value of Infinity is " + Math.ceil(Companion.POSITIVE_INFINITY))
// Negative ∞ infinite value
println("The ceiling value of -Infinity is " + Math.ceil(Companion.NEGATIVE_INFINITY))
}