Skip to content

khawajafarooq/RoundingDecimal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Rounding Double

Playground demonstration for rounding a double number to N places.

How can you use it?

Make it a part of your own extension ⚙

import Foundation

extension Double {
    /// Rounds the double to N number of decimal places
    mutating func round(to places: Int) -> Double {
        let divisor = pow(10.0, Double(places))
        return Darwin.round(self * divisor) / divisor
    }
}

There are multiple ways to achive this but I prefer this way! ✏

Author 🙏🏻

Web: Khawaja Farooq

Twitter: @khfarooq

Medium: @khfarooq

About

Rounding a decimal number in Swift

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages