Seems to be trivial but I couldn't figure out how to prevent the currency value from Rounding in Swift.
Below is my code:
let halfYearlyPrice = 71.99
var perMonthPrice = (halfYearlyPrice as Double) / 6.0
let currencyFormatter = NumberFormatter()
currencyFormatter.usesGroupingSeparator = true
currencyFormatter.numberStyle = .currency
currencyFormatter.locale = Locale.init(identifier: "en-US")
if let formattedPrice = currencyFormatter.string(from: perMonthPrice as NSNumber) {
print("formattedPrice: ", formattedPrice)
print("\(formattedPrice) / month")
}
The output is
formattedPrice: $12.00
$12.00 / month
I'm wondering how can I ensure the formattedPrice is 11.99
?
Thanks in advance.