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

FloatingPointFormatStyle.Percent is inaccurate for Float16 and Float32 values. #33

Closed
oscbyspro opened this issue Feb 19, 2022 · 1 comment
Labels
bug sum ting broke

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Feb 19, 2022

I'm not sure this is solvable on my end. Decimal and Double seem OK.

func testFloat16() {
    let value  = 1.23 as Float16
    let locale = Locale(identifier: "en_US")
    let result = FloatingPointFormatStyle<Float16>.Percent(locale: locale).format(value)
    XCTAssertEqual(result, "123.046875%")
}
func testFloat32() {
    let value  = 1.23 as Float32
    let locale = Locale(identifier: "en_US")
    let result = FloatingPointFormatStyle<Float32>.Percent(locale: locale).format(value)
    XCTAssertEqual(result, "123.000002%")
}
@oscbyspro oscbyspro added the bug sum ting broke label Feb 19, 2022
@oscbyspro
Copy link
Owner Author

Will probably limit the percent style to Decimal and Double.

@oscbyspro oscbyspro changed the title FloatingPointFormatStyle.Percent seems to be inaccurate for Float16 and Float32 values. FloatingPointFormatStyle.Percent is inaccurate for Float16 and Float32 values. Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug sum ting broke
Projects
None yet
Development

No branches or pull requests

1 participant