Enumeration Caseswift 6.0.3Swift

down

Round to the closest allowed value that is less than or equal to the source.

case down

The following example shows the results of rounding numbers using this rule:

(5.2).rounded(.down)
// 5.0
(5.5).rounded(.down)
// 5.0
(-5.2).rounded(.down)
// -6.0
(-5.5).rounded(.down)
// -6.0

This rule is equivalent to the C floor function and implements the roundToIntegralTowardNegative operation defined by the IEEE 754 specification.

Other cases

  • case awayFromZero

    Round to the closest allowed value whose magnitude is greater than or equal to that of the source.

  • case toNearestOrAwayFromZero

    Round to the closest allowed value; if two values are equally close, the one with greater magnitude is chosen.

  • case toNearestOrEven

    Round to the closest allowed value; if two values are equally close, the even one is chosen.

  • case towardZero

    Round to the closest allowed value whose magnitude is less than or equal to that of the source.

  • case up

    Round to the closest allowed value that is greater than or equal to the source.