Swift Tutorial Swift Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Swift - llround() Function



The Swift llround() function returns an integral value that is nearest to the argument value. In halfway cases, the argument is rounded away from zero.

Syntax

In Foundation framework, it is defined as follows:

public func llround(_ __x: Double) -> Int64 

Parameters

x Specify a value to round.

Return Value

Returns an integral value by rounding up the x to nearby integral value then casted to Int64 type.

Example:

In the example below, llround() function is used to round the given number.

import Foundation

print("llround(10.4) = \(llround(10.4))")
print("llround(10.6) = \(llround(10.6))")
print("llround(10.5) = \(llround(10.5))")
print("llround(11.5) = \(llround(11.5))")
print("llround(12.5) = \(llround(12.5))")
print("llround(-10.5) = \(llround(-10.5))")
print("llround(-11.5) = \(llround(-11.5))")
print("llround(-12.5) = \(llround(-12.5))")

The output of the above code will be:

llround(10.4) = 10
llround(10.6) = 11
llround(10.5) = 11
llround(11.5) = 12
llround(12.5) = 13
llround(-10.5) = -11
llround(-11.5) = -12
llround(-12.5) = -13

❮ Swift Math Functions

5