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

Number printing gives error because of f64 conversion #214

Closed
jhoobergs opened this issue Jan 12, 2021 · 3 comments
Closed

Number printing gives error because of f64 conversion #214

jhoobergs opened this issue Jan 12, 2021 · 3 comments
Labels
duplicate good first issue Want to help? Those are great bugs to start with! help wanted We need help making decisions or writing PRs for this.

Comments

@jhoobergs
Copy link

When using variables representing floating numbers, strange situations can arise.
The reason for this is https://docs.rs/fluent-bundle/0.14.0/src/fluent_bundle/types/number.rs.html#178 where everything is converted to a f64.

e.g if you use let v : f32 = 300072.3; and pass v as a FluentValue, it will be shown as 300072.3125 because of f64's higher accuracy.

If you would keep it as a f32, however, it would be shown correctly?

@jhoobergs jhoobergs changed the title String f32 printing behavior? f32 printing behavior? Jan 12, 2021
@zbraniecki zbraniecki added good first issue Want to help? Those are great bugs to start with! help wanted We need help making decisions or writing PRs for this. labels Jan 12, 2021
@zbraniecki
Copy link
Collaborator

Hi! Thanks for reporting!

I'm open to PRs to fix it, and ultimately, we hope to move our numbers formatting to use ICU4X once it gains NumberFormat API.

@jhoobergs jhoobergs changed the title f32 printing behavior? Number printing gives error because of f64 conversion Jan 12, 2021
@jhoobergs
Copy link
Author

jhoobergs commented Jan 12, 2021

I renamed the issue, because the problem is bigger. It can also go wrong for whole numbers, because f64 can't represent all whole numbers.
e.g. 18014398509481985 is printed as 18014398509481984 (one lower).

(explanation at https://stackoverflow.com/a/19474852)

@alerque
Copy link
Collaborator

alerque commented May 6, 2024

This issue is a duplicate of #337. That issue is of course later than this one, but since it has some suggestions of a fix I think I'll close this version no discussion continues elsewhere. There is also icu4x stuff in progress (see #269 and #329) that relates to this. I would suggest subscribing to #337 if you want to be notified when this is fixed.

@alerque alerque closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate good first issue Want to help? Those are great bugs to start with! help wanted We need help making decisions or writing PRs for this.
Projects
None yet
Development

No branches or pull requests

3 participants