take the ceiling of a number in swift

To take the ceiling of a number in Swift, you can use the ceil() function provided by the Swift standard library. This function rounds a floating-point number up to the nearest integer value.

main.swift
let number = 3.14
let ceilingNumber = ceil(number)
print(ceilingNumber) // Output: 4.0
87 chars
4 lines

In this example, the ceil() function takes the number variable and rounds it up to the nearest integer value, which is 4.0. This rounded value is then assigned to the ceilingNumber variable and printed to the console.

gistlibby LogSnag