FloatingPoint
protocol FloatingPoint : Hashable, SignedNumeric, Strideable where Self == Self.Magnitude
-
Mechanica
Returns a
new
roundedFloatingPoint
to specified number of decimalplaces
.Example:
var piFloat = Float(3.141_592_653_589_793_238_46) piFloat.rounded(to: 0) -> 3.0 piFloat.rounded(to: 7) -> 3.1415927 var piFloat80 = Float80(3.14159_26535_89793_23846) piFloat80.rounded(to: 16, rule: .down) -> 3.141_592_653_589_793_2 piFloat80.rounded(to: 16, rule: .up) -> 3.141_592_653_589_793_3
Declaration
Swift
public func rounded(to decimalPlaces: Int, rule: FloatingPointRoundingRule = .toNearestOrAwayFromZero) -> Self
-
Mechanica
Rounds
self
to specified number of decimalplaces
.Example:
var piFloat = Float(3.141_592_653_589_793_238_46) piFloat.round(to: 3) -> piFloat is 3.142 piFloat.round(to: 7) -> piFloat is 3.1415927 var piFloat80 = Float80(3.14159_26535_89793_23846) piFloat80.round(to: 16, rule: .down) -> piFloat80 is 3.141_592_653_589_793_2 piFloat80.round(to: 16, rule: .up) -> piFloat80 is 3.141_592_653_589_793_3
Declaration
Swift
public mutating func round(to decimalPlaces: Int, rule: FloatingPointRoundingRule = .toNearestOrAwayFromZero)
-
Mechanica
Returns a
new
ceiledFloatingPoint
to specified number of decimalplaces
.Example:
var piFloat = Float(3.141_592_653_589_793_238_46) piFloat.ceiled(to: 0) -> 4.0 piFloat.ceiled(to: 5) -> 3.1416
Declaration
Swift
public func ceiled(to decimalPlaces: Int) -> Self
-
Mechanica
Ceils
self
to specified number of decimalplaces
.Example:
var piFloat = Float(3.141_592_653_589_793_238_46) piFloat.ceil(to: 0) -> piFloat is 4.0 piFloat.ceil(to: 5) -> piFloat is 3.1416
Declaration
Swift
public mutating func ceil(to decimalPlaces: Int)
-
Mechanica
Returns a
new
flooredFloatingPoint
to specified number of decimalplaces
.Example:
var piFloat = Float(3.141_592_653_589_793_238_46) piFloat.floored(to: 0) -> 3.0 piFloat.floored(to: 5) -> 3.14159
Declaration
Swift
public func floored(to decimalPlaces: Int) -> Self
-
Mechanica
Floors
self
to specified number of decimalplaces
.Example:
var piFloat = Float(3.141_592_653_589_793_238_46) piFloat.floor(to: 0) -> piFloat is 3.0 piFloat.floor(to: 5) -> piFloat is 3.14159
Declaration
Swift
public mutating func floor(to decimalPlaces: Int)