Creates an integer from the given floating-point value, rounding toward zero.
SDKs
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 6.1+
Framework
- Core Graphics
Declaration
init(_ value: CGFloat)
Parameters
valueA floating-point value to convert to an integer.
valuemust be representable in this type after rounding toward zero.
Discussion
Any fractional part of value is removed, rounding the resulting value toward zero.
let x = Int(21.5 as CGFloat)
// x == 21
let y = Int(-21.5 as CGFloat)
// y == -21