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-12036] Incorrect and inconsistent NumberFormatter behavior for currencies on Linux #3277

Closed
Mordil opened this issue Jan 15, 2020 · 11 comments
Assignees

Comments

@Mordil
Copy link

Mordil commented Jan 15, 2020

Previous ID SR-12036
Radar None
Original Reporter @Mordil
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 5.1.2, 5.2 snapshots, and trunk snapshots

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

md5: bb12216218c8b4e98f1eb9e447dd583e

Issue Description:

The project in reference is Swift Currency. The unit tests that validate the string output from NumberFormatter is failing, but in different ways.

The failing test case:

let pounds = GBP(14928.789)
XCTAssertEqual("\(pounds, forLocale: .init(identifier: "de_DE"))", "14.928,79 £")

The relevant pieces of code:

let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = locale
formatter.currencyCode = money.metadata.alphabeticCode // e.g. "USD"
formatter.string(from: NSDecimalNumber(decimal: money.roundedAmount) // bankers rounding

On Swift 5.0.3 the formatter correctly returns: 14.928,79 £

On Swift 5.1.2: 14.928,79 GBP

On Swift 5.2 snapshot (as of Jan 14, 2019): 14.928,79 €

On the latest trunk (as of Jan 14, 2019): 14.928,79 €

@Mordil
Copy link
Author

Mordil commented Jan 15, 2020

On macOS for 5.1.2, this is behaving correctly: https://github.com/peek-travel/swift-currency/pull/7/checks?check_run_id=390462152

@spevans
Copy link
Collaborator

spevans commented Jan 15, 2020

Is this failing on Linux or macOS or both? The ICU version on Linux was changed recently for `5.2` and `master` and that would probably causes issues. I also remember some of the scl-foundation tests being different between Linux and Catalina around currency.

@Mordil
Copy link
Author

Mordil commented Jan 15, 2020

@spevans This only fails on Linux. macOS (Catalina) with 5.0.3, 5.1.2, and 5.2 snapshot all pass the unit tests correctly.

@Mordil
Copy link
Author

Mordil commented Jan 15, 2020

Does the "regression" where we get the currency identifier, rather than the symbol, from Swift 5 -> 5.1 on Linux have a known reason why it happened?

@spevans
Copy link
Collaborator

spevans commented Jan 15, 2020

The underlying ICU library that does the currency formatting is tied to the OS version on macOS but the Swift version on Linux. Also the Linux version just compiles the default ICU source code, for macOS Apple make some small changes so its hard to compare Swift versions between Linux and macOS for this. As for the regression Im trying to work out whats changed. Its pretty much left to ICU to do the formattering work.

Do you have a complete code segment that I can paste into the REPL to check the output? Hopefully I can then convert it into a unit test for scl-foundation

@Mordil
Copy link
Author

Mordil commented Jan 16, 2020

@spevans I've attached a project with a failing unit test.

@spevans
Copy link
Collaborator

spevans commented Jan 16, 2020

The issue looks to be that when no currencySymbol is set, the .locale's .currencySymbol is preferred over the formatter's currencySymbol.

#2614 should fix this

@Mordil
Copy link
Author

Mordil commented Jan 21, 2020

@spevans Is it still possible to ship this in 5.2? If there's a 5.1.5, is it possible to fix this then as well?

@spevans
Copy link
Collaborator

spevans commented Jan 21, 2020

It should be ok for 5.1/5.2 as it is a clear bug fix so just need to make sure the backport PR is approved in time.

The fix should be in the nightly snapshot swift-DEVELOPMENT-SNAPSHOT-2020-01-20-a, can you confirm it works for you then I will sort out the backport.

@Mordil
Copy link
Author

Mordil commented Jan 21, 2020

@spevans I have pulled the latest trunk snapshot, and my unit tests are passing again! Thanks 🙂

@spevans
Copy link
Collaborator

spevans commented Jan 21, 2020

Thanks for testing I will open a backport PR.

@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