Instance Method インスタンスメソッド

rounded()

Returns this value rounded to an integral value using “schoolbook rounding.” 「教科書丸め」を使って整数値に丸めたこの値を返します。

Declaration 宣言

func rounded() -> Float

Return Value 戻り値

The nearest integral value, or, if two integral values are equally close, the integral value with greater magnitude. 最も近い整数値、または、2つの整数値が同じくらい近いならば、より大きい規模を持つ整数値。

Discussion 解説

The rounded() method uses the .toNearestOrAwayFromZero rounding rule, where a value halfway between two integral values is rounded to the one with greater magnitude. The following example rounds several values using this default rule: rounded()メソッドは.toNearestOrAwayFromZero丸め規則を使います、そこでは2つの整数値の間の中ほどの値はより大きい規模を持つものへと丸められます。以下の例はいくつかの値をこの初期設定での規則を使って丸めます:


(5.2).rounded()
// 5.0
(5.5).rounded()
// 6.0
(-5.2).rounded()
// -5.0
(-5.5).rounded()
// -6.0

To specify an alternative rule for rounding, use the rounded(_:) method instead. 丸めのための代替の規則を指定するには、rounded(_:)メソッドを代わりに使ってください。

See Also 参照

Rounding Values 値を丸める