<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCoder/decodeFloat(forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCoder(im)decodeFloatForKey:"
  },
  "title" : "decodeFloat(forKey:)"
}
-->

# decodeFloat(forKey:)

Decodes and returns a float value that was previously encoded with [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-84cez) or [`encode(_:forKey:)`](/documentation/Foundation/NSCoder/encode(_:forKey:)-9xiiu) and associated with the string `key`.

```
func decodeFloat(forKey key: String) -> Float
```

## Discussion

If the value was encoded as a double, the extra precision is lost. If the encoded real value does not fit into a float, the method raises an `NSRangeException`. Subclasses must override this method if they perform keyed coding.

---

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)