Swift - llrint() Function
The Swift llrint() function returns an integral value by rounding up the specified number. If x falls exactly at the midway between two integers, the even integer is returned.
Syntax
In Foundation framework, it is defined as follows:
public func llrint(_ __x: Double) -> Int64
Parameters
x |
Specify a value to round. |
Return Value
Returns the value of x which is first rounded to nearby integral value then casted to Int64 type. If x falls exactly at the midway between two integers, the even integer is returned.
Example:
In the example below, llrint() function is used to round the given number.
import Foundation print("llrint(10.4) = \(llrint(10.4))") print("llrint(10.6) = \(llrint(10.6))") print("llrint(10.5) = \(llrint(10.5))") print("llrint(11.5) = \(llrint(11.5))") print("llrint(12.5) = \(llrint(12.5))")
The output of the above code will be:
llrint(10.4) = 10 llrint(10.6) = 11 llrint(10.5) = 10 llrint(11.5) = 12 llrint(12.5) = 12
❮ Swift Math Functions