NumberFormatter produces incorrect results when using numbers close to UInt.max

Originator:lindahl22
Number:rdar://FB8643741 Date Originated:Sep 6, 2020 at 7:22 PM
Status:Open Resolved:
Product:Foundation Product Version:
Classification: Reproducible:macOS 10.15.5, iOS 13.6.1
 
When formatting numbers close to UInt.max `NumberFormatter` produces the incorrect result.

Gist: https://gist.github.com/michaellindahl/73b5cb0e998940d974535f570f2d9cc5

// Create a number formatter 
let formatter = NumberFormatter()
formatter.numberStyle = .decimal

// Then compare the results
let formattedString = formatter.string(for: UInt.max - 100)
let stringInterpolation = "\(UInt.max - 100)"

Using UInt.max
String interpolation: 18446744073709551615
Number Formatter: Optional("-1")

Using UInt.max - 100
String interpolation: 18446744073709551515
Number Formatter: Optional("-101")

Using UInt.max / 10
String interpolation: 1844674407370955161
Number Formatter: Optional("1,844,674,407,370,955,161")

Using UInt.max / 100
String interpolation: 184467440737095516
Number Formatter: Optional("184,467,440,737,095,516")

Using 18446744073709551615
String interpolation: 18446744073709551615
Number Formatter: Optional("-1")

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!