Below is how I would have previously truncated a float to two decimal places
NSLog(@\" %.02f %.02f %.02f\", r, g, b);
I checked the docs an
Swift 4 Xcode 10 Update
extension Double { var asNumber:String { if self >= 0 { let formatter = NumberFormatter() formatter.numberStyle = .none formatter.percentSymbol = "" formatter.maximumFractionDigits = 2 return "\(formatter.string(from: NSNumber(value: self)) ?? "")" } return "" } }