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

# init(exactly:)

Creates an integer from the given floating-point value, if it can be
represented exactly.

```
init?(exactly source: Float)
```

## Parameters

`source`

A floating-point value to convert to an integer.

## Discussion

If the value passed as `source` is not representable exactly, the result
is `nil`. In the following example, the constant `x` is successfully
created from a value of `21.0`, while the attempt to initialize the
constant `y` from `21.5` fails:

```
let x = Int(exactly: 21.0)
// x == Optional(21)
let y = Int(exactly: 21.5)
// y == 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)