Skip to content
Snippets Groups Projects
Unverified Commit f76890cc authored by GyDi's avatar GyDi
Browse files

fix: parse bytes base 1024

parent e1c8f1fe
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,8 @@ const UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const parseTraffic = (num: number) => {
if (num < 1000) return [`${Math.round(num)}`, "B"];
const exp = Math.min(Math.floor(Math.log10(num) / 3), UNITS.length - 1);
const ret = (num / Math.pow(1000, exp)).toPrecision(3);
const exp = Math.min(Math.floor(Math.log2(num) / 10), UNITS.length - 1);
const ret = (num / Math.pow(1024, exp)).toPrecision(3);
const unit = UNITS[exp];
return [ret, unit];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment