fluent-rs icon indicating copy to clipboard operation
fluent-rs copied to clipboard

Number printing gives error because of f64 conversion

Open jhoobergs opened this issue 5 years ago • 2 comments

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 avatar Jan 12 '21 16:01 jhoobergs

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.

zbraniecki avatar Jan 12 '21 16:01 zbraniecki

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)

jhoobergs avatar Jan 12 '21 16:01 jhoobergs