mirror of
https://github.com/Telecominfraproject/wlan-cloud-ui.git
synced 2025-11-03 12:18:08 +00:00
Use absolute value of bytes when determining exponent
This commit is contained in:
@@ -13,7 +13,7 @@ function formatBytes(bytes, decimals = 2) {
|
|||||||
const dm = decimals < 0 ? 0 : decimals;
|
const dm = decimals < 0 ? 0 : decimals;
|
||||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
const i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(k));
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-properties
|
// eslint-disable-next-line no-restricted-properties
|
||||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i] || ''}`;
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i] || ''}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user