NumberFormatter on iOS 15

let formatter = NumberFormatter()
        formatter.numberStyle = .decimal
        formatter.minimumFractionDigits = 18
        formatter.maximumFractionDigits = 18
        formatter.roundingMode = .floor
        
        let number = NSDecimalNumber(string: "6.381569271192148411")
        let result = formatter.string(from: number)
        print(result!)

iOS 15: 6.381569271192150000

iOS 14: 6.381569271192148411

Do you have a question?

I tested with Xcode 13.2ß2 in Playground. Effectively get the same result as you.

I changed for this:

let formatter = NumberFormatter()
formatter.usesSignificantDigits = true
formatter.minimumSignificantDigits = 18
formatter.maximumSignificantDigits = 20

let number = NSDecimalNumber(string: "6.381569271192148411")
let result = formatter.string(from: number)

print("result", result!)

I get:

  • result 6.381569271192148411

So correct result, but don't know what changed in API in iOS 15. Could ask support.

Also encountered this issue with iOS 15 after moving to xcode 13. Made a feedback report: FB9840346

Anyone has any idea what's happening here?

The workaround above isnt exactly right, because maximumSignificantDigits property is widely different from maximumFractionDigits

NumberFormatter on iOS 15
 
 
Q