Swift Double rounded()

The rounded() method rounds the specified value to the closest int or long value and returns it. That is, 3.87 is rounded to 4 and 3.24 is rounded to 3.

Example


rounded() Syntax

The syntax of the rounded() method is:

num.rounded()

Here, num is a number.


rounded() Parameters

The rounded() method doesn't take any parameters.


rounded() Return Values

The rounded() method returns the nearest integral value.


Example: Swift Double rounded()

Output

2.0
2.0
1.0

Here, the values are rounded to their nearest integral using the rounded() method.