Skip to content
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

Merged
merged 1 commit into from
Jun 14, 2024
Merged

refactor(web): byte unit utils #10332

merged 1 commit into from
Jun 14, 2024

Conversation

danieldietzler
Copy link
Member

Simplify byte utils using ✨ Math ✨

Copy link
Contributor

@michelheusschen michelheusschen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment on lines 22 to 24
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];
Copy link
Contributor

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.

Suggested change
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];

Copy link
Member Author

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!

@danieldietzler danieldietzler force-pushed the refactor/unit-conversion-web branch from 3534ba4 to f3cf924 Compare June 14, 2024 17:22
@jrasm91 jrasm91 enabled auto-merge (squash) June 14, 2024 17:26
@jrasm91 jrasm91 merged commit c896fe3 into main Jun 14, 2024
22 checks passed
@jrasm91 jrasm91 deleted the refactor/unit-conversion-web branch June 14, 2024 17:27
@aviv926
Copy link
Contributor

aviv926 commented Jul 6, 2024

@danieldietzler Could this change affect #10927?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants