I want to specify my (slider) double to 2 decimals but xcode won't let me do that:
return (Double(pris, specifier: "%.2f"))
And i don't want to convert it into a string and then format it because numbers like 600000000 are then unreadable.
I have tried solutions like :
extension Double {
// Rounds the double to 'places' significant digits
func roundTo(places:Int) -> Double {
guard self != 0.0 else {
return 0
}
let divisor = pow(10.0, Double(places) - ceil(log10(fabs(self))))
return (self * divisor).rounded() / divisor
}
}