<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Double/rounded(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SFsE7roundedyxs25FloatingPointRoundingRuleOF::SYNTHESIZED::s:Sd"
  },
  "title" : "rounded(_:)"
}
-->

# rounded(_:)

Returns this value rounded to an integral value using the specified
rounding rule.

```
func rounded(_ rule: FloatingPointRoundingRule) -> Self
```

## Parameters

`rule`

The rounding rule to use.

## Return Value

The integral value found by rounding using `rule`.

## Discussion

The following example rounds a value using four different rounding rules:

```
let x = 6.5

// Equivalent to the C 'round' function:
print(x.rounded(.toNearestOrAwayFromZero))
// Prints "7.0"

// Equivalent to the C 'trunc' function:
print(x.rounded(.towardZero))
// Prints "6.0"

// Equivalent to the C 'ceil' function:
print(x.rounded(.up))
// Prints "7.0"

// Equivalent to the C 'floor' function:
print(x.rounded(.down))
// Prints "6.0"
```

For more information about the available rounding rules, see the
`FloatingPointRoundingRule` enumeration. To round a value using the
default “schoolbook rounding” of `.toNearestOrAwayFromZero`, you can use
the shorter `rounded()` method instead.

```
print(x.rounded())
// Prints "7.0"
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)