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
import Foundation extension CGFloat { var string1: String { return String(format: "%.1f", self) } var string2: String { return String(format: "%.2f", self) } }
let offset = CGPoint(1.23, 4.56) print("offset: \(offset.x.string1) x \(offset.y.string1)") // offset: 1.2 x 4.6