take the floor of a number in swift

To take the floor of a number in Swift, you can use the floor() function from the Foundation module. Here's an example:

main.swift
import Foundation

let x = 3.7
let y = floor(x) // y will be 3.0
65 chars
5 lines

In this example, x is a Double value, and we use floor(x) to get the nearest integer value less than or equal to x. The result is assigned to y.

Note that you need to import the Foundation module to use the floor() function.

related categories

gistlibby LogSnag