NSNumberFormatter ignores maximumFractionDigits after changing currencySymbol
| Originator: | glen.tregoning | ||
| Number: | rdar://18034852 | Date Originated: | 15/7/2014 |
| Status: | Open | Resolved: | |
| Product: | iOS | Product Version: | |
| Classification: | Reproducible: |
FYI: If we set currencyFormatter.internationalCurrencySymbol as well, the maximumFractionDigits performs as expected
Summary:
NSNumberFormatter ignores maximumFractionDigits after changing currencySymbol from "£" to "$" between stringFromNumber calls
Steps to Reproduce:
Example Code (see attached Playground as well)
// Example of issue where maximumFractionDigits doesn't get honoured after changing currency styles across usage.
// Playground - noun: a place where people can play
import UIKit
let amounts = [
[ "amount" : 42508, "symbol" : "£"],
[ "amount" : 317265, "symbol" : "$"]
]
let currencyFormatter = NSNumberFormatter()
currencyFormatter.numberStyle = .CurrencyStyle
currencyFormatter.maximumFractionDigits = 0
for amount in amounts {
currencyFormatter.currencySymbol = amount["symbol"] as? String
println(currencyFormatter.stringFromNumber(amount["amount"] as NSNumber))
}
Expected Results:
Expected output:
£42,508
$317,265
Actual Results:
Actual (not the extra .00 on the second line)
£42,508
$317,265.00
Version:
iOS 8.0 Beta 5
Notes:
See attached playground for working demonstration (run on XCode 6 Beta 5).
Also not this is reproducible in Objective C and Swift.
Configuration:
iPhone 5 running iOS8, iPhone Simulator
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Bug marked by Apple as duplicate of rdar://9448011
More details on this Apple Developer forum thread: https://forums.developer.apple.com/message/180172
Possibly duplicated in rdar://28356798.