Skip to content

fix: show a size that rounds up to 10 without a decimal place - #640

Merged
bootandy merged 1 commit into
bootandy:masterfrom
kevin9327:display-round-to-ten
Nov 1, 2026
Merged

bootandy merged 1 commit into
bootandy:masterfrom
kevin9327:display-round-to-ten

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

human_readable_number prints one decimal place for sizes under 10 units and none from 10 up. The < 10 check uses integer division, but the decimal branch rounds with {:.1}, so a size from 9.95 to 9.99 units passes the check and then rounds up to 10.0:

human_readable_number(10239, "")   -> "10.0Ki"   (10240 gives "10Ki")
human_readable_number(9999, "si")  -> "10.0K"    (10000 gives "10K")

The same happens at every unit (10.0Mi, 10.0G, ...). Those sizes now print as 10Ki / 10K, the same as the sizes just above them. Everything else is unchanged.

Tests: new cases in test_human_readable_number_si fail before the change (left: "10.0Ki", right: "10Ki") and pass after; cargo test (all suites) and cargo fmt --check pass.

AI assistance: I used an AI coding assistant to help find and write this change. I reviewed the code and tests and ran them myself.

@bootandy

bootandy commented Nov 1, 2026

Copy link
Copy Markdown
Owner

that is an interesting edge case. thanks!

@bootandy
bootandy merged commit eac0766 into bootandy:master Nov 1, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants