Instance Method

round()

Rounds this value to an integral value using “schoolbook rounding.”

Declaration

mutating func round()

Discussion

The round() method uses the .toNearestOrAwayFromZero rounding rule, where a value halfway between two integral values is rounded to the one with greater magnitude. The following example rounds several values using this default rule:

var x = 5.2
x.round()
// x == 5.0
var y = 5.5
y.round()
// y == 6.0
var z = -5.5
z.round()
// z == -6.0

To specify an alternative rule for rounding, use the round(_:) method instead.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software