Initializer

init(_:)

Creates an integer from the given floating-point value, rounding toward zero.

Declaration

init(_ value: CGFloat)

Parameters

value

A floating-point value to convert to an integer. value must 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

See Also

Converting Floating-Point Values

init<T>(T)

Creates an integer from the given floating-point value, rounding toward zero. Any fractional part of the value passed as source is removed.

init?<T>(exactly: T)

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

init(Double)

Creates an integer from the given floating-point value, rounding toward zero.

init(Float)

Creates an integer from the given floating-point value, rounding toward zero.

init(Float80)

Creates an integer from the given floating-point value, rounding toward zero.

init?(exactly: Double)

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

init?(exactly: Float)

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

init?(exactly: Float80)

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