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-14286] NumberFormatter fraction digits not working properly on Linux #4221

Open
swift-ci opened this issue Feb 28, 2021 · 3 comments · May be fixed by #4647
Open

[SR-14286] NumberFormatter fraction digits not working properly on Linux #4221

swift-ci opened this issue Feb 28, 2021 · 3 comments · May be fixed by #4647

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14286
Radar rdar://problem/74876581
Original Reporter telcy (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: a4782b0fbf861d51211b3b3e8dcbc568

Issue Description:

import Foundation

let formatter = NumberFormatter()
formatter.minimumIntegerDigits = 1
formatter.minimumFractionDigits = 1
formatter.maximumFractionDigits = 8

let value: Double = 0.01473643000000003
let formattedValue = formatter.string(from: value as NSNumber)!

print(formattedValue)


// macOS => 0.01473643
// Linux => 0.0
@swift-ci
Copy link
Contributor Author

Comment by Ken Harris (JIRA)

In swift-corelibs-foundation, NumberFormatter only seems to apply maximumFractionDigits when minimumFractionDigits<=0:

https://github.com/apple/swift-corelibs-foundation/blob/main/Sources/Foundation/NumberFormatter.swift#L144-L146

Sure enough, when minimumFractionDigits is set to -1, it prints the expected string.

I see no explanation for this extra check. It was there from the initial NSNumberFormatter.swift commit.

TestNumberFormatter.swift has tests for minimumFractionDigits and maximumFractionDigits but never both at the same time.

@typesanitizer
Copy link

@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
ochococo added a commit to ochococo/swift-corelibs-foundation that referenced this issue Oct 20, 2022
NumberFormatter should accept both `minimumFractionDigits` and `maximumFractionDigits` at the same time, issue:
apple#4221

Signed-off-by: Oktawian Chojnacki <oktawian@me.com>
@ochococo ochococo linked a pull request Oct 20, 2022 that will close this issue
@YOCKOW YOCKOW linked a pull request Nov 4, 2022 that will close this issue
@ArEnSc
Copy link

ArEnSc commented Feb 10, 2023

it's also not working in iOS Land wtf is going on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants