-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(web): byte unit utils #10332
Conversation
003b1fb
to
3534ba4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
web/src/lib/utils/byte-units.ts
Outdated
const magnitude = Math.floor(Math.log2(bytes === 0 ? 1 : bytes) / 10); | ||
|
||
return [remainder, units[magnitude]]; | ||
return [Number.parseFloat((bytes / 2 ** (magnitude * 10)).toFixed(maxPrecision)), magnitude]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use base 1024 for these functions? But this isn't wrong at all.
const magnitude = Math.floor(Math.log2(bytes === 0 ? 1 : bytes) / 10); | |
return [remainder, units[magnitude]]; | |
return [Number.parseFloat((bytes / 2 ** (magnitude * 10)).toFixed(maxPrecision)), magnitude]; | |
const magnitude = Math.floor(Math.log(bytes === 0 ? 1 : bytes) / Math.log(1024)); | |
return [Number.parseFloat((bytes / 1024 ** magnitude).toFixed(maxPrecision)), magnitude]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah we could, good idea!
3534ba4
to
f3cf924
Compare
@danieldietzler Could this change affect #10927? |
Simplify byte utils using ✨ Math ✨