Skip to content

filesizeformat filter's accuracy very limited #563

@seijikun

Description

@seijikun

Describe the bug
The filesizeformat filter internally uses f32. Unfortunately, that's not accurate enough for many common values.

To Reproduce
Add the following 2 assertions to the unit-test test_filesizeformat():

assert_eq!(filesizeformat(300.0 * 1000.0 * 1000.0 * 1000.0).unwrap().to_string(), "300 GB");
assert_eq!(filesizeformat(600.0 * 1000.0 * 1000.0 * 1000.0).unwrap().to_string(), "600 GB");

Result:

thread 'filters::humansize::test_filesizeformat' panicked at askama/src/filters/humansize.rs:124:5:
assertion `left == right` failed
  left: "299.99 GB"
 right: "300 GB"

Now, I could just replace f32 with f64. That makes it go away, but I don't know if that change makes every case go away. And since it looks rather ... optimized, I don't really dare to touch it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions