[Solved] Dynamic trim double [closed]


This code will work for removing trailing zeros

let distanceFloat1: Float = 1.10
let distanceFloat2: Float = 0.10101010101

print("Value \(distanceFloat1.clean)")

print("Value \(distanceFloat2.clean)") 

extension Float {
    var clean: String {
       return self.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self)
    }
}

Output

Value 1.1
Value 1.101010

if you want to remove trailing zeros, also want to remove decimals after x place use

Swift – Remove Trailing Zeros From Double

5

solved Dynamic trim double [closed]