If you have code such as this, then p
will be "2.99"
:
let price = 2.99
let p = String(format: "%.2f", price)
However, if you have code like this:
let priceNS: NSDecimalNumber = 2.99
let p2 = String(format: "%.2f", priceNS)
Then p2
is "0.00"
.
How can you format an NSDecimalNumber
into a string like this? (NSDecimalNumber
is how the price in an SKProduct
is stored)
Decimal
rather thanNSDecimalNumber
in Swift. – Woozy