mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 03:32:36 +08:00
fix: parse bytes base 1024
This commit is contained in:
parent
e1c8f1fed9
commit
f76890cc56
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue
Block a user