You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
NumberFormatter not respecting decimal numberStyle.
Steps to reproduce
import UIKit
extension String {
func toDecimalWithAutoLocale() -> Decimal? {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
// Explicitly tell the formatter to generate decimal numbers
formatter.generatesDecimalNumbers = true
formatter.locale = Locale(identifier: "en_US")
if let number = formatter.number(from: self) as? NSDecimalNumber {
return number as Decimal
}
// If none work, return nil
return nil
}
}
if let decimalValue = "9.20".toDecimalWithAutoLocale() {
print("Decimal value:", decimalValue) // Should print: Decimal value: 9.20
} else {
print("Could not parse decimal value.")
}
Output = Decimal value: 9.199999999999999
Expected behavior
The output should be "9.20"
Environment
Swift compiler version info swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1) Target: arm64-apple-macosx14.0
Xcode version info Xcode 15.0 Build version 15A240d
Deployment target: Playground
The text was updated successfully, but these errors were encountered:
Description
NumberFormatter not respecting decimal numberStyle.
Steps to reproduce
Output =
Decimal value: 9.199999999999999
Expected behavior
The output should be "9.20"
Environment
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1) Target: arm64-apple-macosx14.0
Xcode 15.0 Build version 15A240d
The text was updated successfully, but these errors were encountered: