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-10525] Decimal(string:locale:) different results macOS vs Linux #3431

Closed
swift-ci opened this issue Apr 19, 2019 · 2 comments
Closed

[SR-10525] Decimal(string:locale:) different results macOS vs Linux #3431

swift-ci opened this issue Apr 19, 2019 · 2 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-10525
Radar None
Original Reporter pitfield (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 5.0 (swift-5.0-RELEASE) Target: x86_64-unknown-linux-gnu on Ubuntu 18.04 Server

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3) Target: x86_64-apple-darwin18.5.0 on macOS 10.14.4

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

md5: 273a3e1b9d3ab06690912aaf916a086f

relates to:

  • SR-5326 Decimal(string:locale:) doesn't fail when the entire string isn't parsable

Issue Description:

Decimal(string:locale) produces different results on macOS vs Linux. On macOS, it expects a localized decimal separator in the supplied string, whereas on Linux it expects the decimal separator to be "."

Steps to reproduce

import Foundation

let en_US = Locale(identifier: "en_US")
let fr_FR = Locale(identifier: "fr_FR")

var s = "1234.5678"
print("\(s) with en_US: \(Decimal(string: s, locale: en_US))")
print("\(s) with fr_FR: \(Decimal(string: s, locale: fr_FR))")

s = "1234,5678"
print("\(s) with en_US: \(Decimal(string: s, locale: en_US))")
print("\(s) with fr_FR: \(Decimal(string: s, locale: fr_FR))")

Output on macOS

1234.5678 with en_US: Optional(1234.5678)
1234.5678 with fr_FR: Optional(1234)
1234,5678 with en_US: Optional(1234)
1234,5678 with fr_FR: Optional(1234.5678)

Output on Linux

1234.5678 with en_US: Optional(1234.5678)
1234.5678 with fr_FR: Optional(1234.5678)
1234,5678 with en_US: Optional(1234)
1234,5678 with fr_FR: Optional(1234)

The API doc does not specify which behavior is correct. However, in my opinion, the macOS output is more correct since the initializer has a Locale parameter.

Environment

Linux

  • Ubuntu 18.04 server

  • Swift version 5.0 (swift-5.0-RELEASE) Target: x86_64-unknown-linux-gnu

macOS

  • macOS 10.14.4

  • Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3) Target: x86_64-apple-darwin18.5.0

@swift-ci
Copy link
Contributor Author

Comment by David Pitfield (JIRA)

Related to SR-5326 (but not a dupe).

@spevans
Copy link
Collaborator

spevans commented Apr 22, 2019

#2155

@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
This issue was closed.
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