Skip to content

Changed precision for default localeOptions#88

Merged
sindresorhus merged 4 commits intosindresorhus:mainfrom
siddhant-nair:fixing-issue-82
Aug 12, 2025
Merged

Changed precision for default localeOptions#88
sindresorhus merged 4 commits intosindresorhus:mainfrom
siddhant-nair:fixing-issue-82

Conversation

@siddhant-nair
Copy link
Contributor

Fixes #82

Was getting wrong results for 1023 and 1001 in default settings due to low precision.

Changed default to the precision of the integer part of the number because 1020 B is a huge round off from 1023 B.

@sindresorhus
Copy link
Owner

Should this only be done when using the binary option?

@siddhant-nair
Copy link
Contributor Author

siddhant-nair commented Aug 5, 2025

This logic actually wont interfere with non binary numbers in general, since after any 999 value the next value defaults to the next highest unit.

However in a case such as:

// with old code
prettyBytes(827181 * 10e25) // --> 82700000 YB

// with new code
prettyBytes(827181 * 10e25) // --> 82718100 YB

User gets an accurate value

@sindresorhus
Copy link
Owner

However in a case such as:

Can you add a test case for that?

@siddhant-nair
Copy link
Contributor Author

There you go

@sindresorhus sindresorhus merged commit c9fd951 into sindresorhus:main Aug 12, 2025
2 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.

Rounding bug between 1001 and 1023 in binary mode

2 participants