The CGFloat
is just a number (so 17.3
and 17.30
is the same value for it); what you're really concerned is how to set the String
representation of your CGFloat
number.
As an alternative to @vadian:s solution, you can make use of an NSNumberFormatter
as follows
/* Your CGFloat example */
let str = "17.30"
let flt = CGFloat((str as NSString).doubleValue) + 2.0
/* Use NSNumberFormatter to display your CGFloat
with exactly 2 fraction digits. */
let formatter = NSNumberFormatter()
formatter.maximumFractionDigits = 2
formatter.minimumFractionDigits = 2
print(formatter.stringFromNumber(flt)!)
/* 19.30 */