SwiftExtension // Add Double.rounded(toPlaces:).

This commit is contained in:
ShikiSuen 2022-11-18 15:17:07 +08:00
parent efed9c0723
commit 5d98194076
1 changed files with 10 additions and 0 deletions

View File

@ -136,6 +136,16 @@ public struct AppProperty<Value> {
}
}
// MARK: -
// Ref: https://stackoverflow.com/a/32581409/4162914
extension Double {
public func rounded(toPlaces places: Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded() / divisor
}
}
// MARK: - String RegReplace Extension
// Ref: https://stackoverflow.com/a/40993403/4162914 && https://stackoverflow.com/a/71291137/4162914