Post

Replies

Boosts

Views

Activity

Reply to How to get a Double with two decimal points without round?
I just created a function that can help... 3 years later, but I hope it can help someone looking for the answer: func convert(_ a: Double, maxDecimals max: Int) -> Double {     let stringArr = String(a).split(separator: ".")     let decimals = Array(stringArr[1])     var string = "\(stringArr[0])."     var count = 0;     for n in decimals {         if count == max { break }         string += "\(n)"         count += 1     }     let double = Double(string)!     return double }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’22