<!--
{
  "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/init(exactly:)-2l6p1",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sd7exactlySdSgSd_tcfc"
  },
  "title" : "init(exactly:)"
}
-->

# init(exactly:)

Creates a new instance initialized to the given value, if it can be
represented without rounding.

```
init?(exactly other: Double)
```

## Parameters

`other`

The value to use for the new instance.

## Discussion

If `other` can’t be represented as an instance of `Double` without
rounding, the result of this initializer is `nil`. In particular,
passing NaN as `other` always results in `nil`.

```
let x: Double = 21.25
let y = Double(exactly: x)
// y == Optional.some(21.25)

let z = Double(exactly: Double.nan)
// z == nil
```

---

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)