Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5326] Decimal(string:locale:) doesn't fail when the entire string isn't parsable #3840

Open
bobergj opened this issue Jun 28, 2017 · 1 comment
Assignees

Comments

@bobergj
Copy link

bobergj commented Jun 28, 2017

Previous ID SR-5326
Radar rdar://problem/33036250
Original Reporter @bobergj
Type Bug
Environment

Xcode Version 11.0 beta 4 (11M374r), Apple Swift version 5.1 (swiftlang-1100.0.257.2 clang-1100.0.31.3)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @itaiferber
Priority Medium

md5: 20e3c7252ef6c20876ade0ae4006c86a

relates to:

  • SR-10525 Decimal(string:locale:) different results macOS vs Linux

Issue Description:

Decimal init?(string: String, locale: Locale? = default) doesn't return nil when the string format doesn't match the locale. Such as the comma separator being different. It just seems to parse the longest possible prefix.
I note that NSDecimalNumber init(string:locale🙂 has the same behaviour, although that initialiser isn't failable.

import Foundation

let stringWithCommaSeparator = "1,0"
let decimal1 = Decimal(string: stringWithCommaSeparator, locale: Locale(identifier: "en_US"))
let nsDecimalNumber1 = NSDecimalNumber(string: stringWithCommaSeparator, locale: Locale(identifier: "en_US"))

let stringWithDotSeparator = "1.1"
let decimal2 = Decimal(string: stringWithDotSeparator, locale: Locale(identifier: "en_US"))
let nsDecimalNumber2 = NSDecimalNumber(string: stringWithDotSeparator, locale: Locale(identifier: "en_US"))

in playground prints:

"1.0"
1            (expected: nil)
1            (expected: nil)

"1.1"
1.1
1.1
@itaiferber
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants