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-13952] Nil value from Number Formatter #3963

Open
swift-ci opened this issue Dec 10, 2020 · 5 comments
Open

[SR-13952] Nil value from Number Formatter #3963

swift-ci opened this issue Dec 10, 2020 · 5 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-13952
Radar rdar://problem/72183860
Original Reporter dimitri.strauneanu (JIRA User)
Type Bug
Environment

Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial

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

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, ICU, Linux
Assignee None
Priority Medium

md5: e9e8d7e301b891b7980c160325f3757c

Issue Description:

Running the following code gives different results for MacOS and Ubuntu 16.04.

let identifier = "en_RO"
let price = "99,55"

let formatter = NumberFormatter()
formatter.locale = Locale(identifier: identifier)
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 2

print(String(describing: formatter.number(from: price)))

MacOS with Swift version:
Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.6.0
Output: {code:swift}Optional(99.55)

Ubuntu 16.04 with Swift version:
Swift version 5.3.1 (swift-5.3.1-RELEASE)
Target: x86_64-unknown-linux-gnu
Output: {code:swift}nil
@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Contributor Author

Comment by Dimitri Strauneanu (JIRA)

Any updates here? Is there any possible workaround for now? This is a real blocker.

@gwynne
Copy link
Contributor

gwynne commented Dec 15, 2020

Confirmed this discrepancy also appears between Xcode 12.3 and the latest 5.3 Focal image:

$ swift
Welcome to Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28).
Type :help for assistance.
  1> import Foundation
  2> let identifier = "en_RO"
  3. let price = "99,55"
  4.
  5. let formatter = NumberFormatter()
  6. formatter.locale = Locale(identifier: identifier)
  7. formatter.numberStyle = .decimal
  8. formatter.maximumFractionDigits = 2
  9.
 10. print(String(describing: formatter.number(from: price)))
Optional(99.55)
 11> ^D
$ docker run -ti --rm --privileged swift:5.3-focal
root@e25849567a2d:/# swift
Welcome to Swift version 5.3.1 (swift-5.3.1-RELEASE).
Type :help for assistance.
  1> import Foundation
  2> let identifier = "en_RO"
  3. let price = "99,55"
  4.
  5. let formatter = NumberFormatter()
  6. formatter.locale = Locale(identifier: identifier)
  7. formatter.numberStyle = .decimal
  8. formatter.maximumFractionDigits = 2
  9.
 10. print(String(describing: formatter.number(from: price)))
nil

@gwynne
Copy link
Contributor

gwynne commented Dec 15, 2020

Based on the results of querying the Locale object (the decimalSeparator and groupingSeparator properties), it looks like the locale data for en_RO is incorrect - is this possibly an issue in ICU?

@spevans
Copy link
Collaborator

spevans commented Dec 16, 2020

It looks to be an ICU issue on Linux. The en_RO locale isnt in the list of available locales on Linux but is on macOS. Note that macOS uses a slightly different version of ICU, where Apple ship some local changes to the published versions. Linux uses the default publised versions.

@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

4 participants