Initializer

init(exactly:)

Creates an integer from the given floating-point value, if it can be represented exactly. 与えられた浮動小数点値から整数を作成します、もしそれが正確に表現可能ならば。

Declaration 宣言

init?(exactly source: Double)

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: sourceとして渡された値が正確に表現可能でないならば、結果はnilです。続く例において、定数x21.0の値から首尾よく作成されます、一方で定数y21.5から初期化する試みは失敗します:


let x = Int(exactly: 21.0)
// x == Optional(21)
let y = Int(exactly: 21.5)
// y == nil