WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@watilde
Copy link
Contributor

@watilde watilde commented Dec 8, 2025

WHY/WHAT

Fixed non-intuitive unit rounding for byte formatting. Previously, values close to a unit boundary (e.g. 999,999 B) displayed incorrectly as the smaller unit. We adjusted the conversion threshold (e.g. to 999,950 B for MB) to leverage standard toFixed(1) rounding, ensuring values that are almost 1.0 of the next unit are correctly displayed as 1.0 MB, prioritizing a better user experience.

@watilde watilde requested a review from a team as a code owner December 8, 2025 23:00
@wraithgar
Copy link
Member

Why was this only done for two of the units?

@watilde
Copy link
Contributor Author

watilde commented Dec 10, 2025

This fix prevents inconsistencies caused by toFixed(1) rounding.
e.g. preventing 999.95 from displaying as "1000.0".

Why was this only done for two of the units?

  • kB → MB / MB → GB (Fixed): Previously, 999,950 bytes (999.95 kB) rounded up to 1000.0 kB. I lowered the threshold to ensure these values switch to the next unit (e.g., 1.0 MB) instead.
  • Bytes → kB (No fix): Bytes are integers (999 B → 1000 B), so fractional rounding issues do not occur.
  • GB → TB (No fix): The current logic only supports up to GB, so no upper transition exists.

@watilde
Copy link
Contributor Author

watilde commented Dec 10, 2025

rebase on the latest and added the tests to tar as suggested

@wraithgar wraithgar changed the title fix(utils): correct byte formatting boundaries for rounding fix: more intuitive byte formatting boundaries for rounding Dec 11, 2025
@wraithgar wraithgar merged commit f2c3af7 into npm:latest Dec 11, 2025
21 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