mirror of
https://github.com/optim-enterprises-bv/OptimCloud-gw-ui.git
synced 2025-11-03 03:37:45 +00:00
CleanBytesString now deals with decimals
This commit is contained in:
@@ -2,11 +2,13 @@ export const cleanTimestamp = (timestamp) => {
|
|||||||
return timestamp.replace('T', ' ').replace('Z', ' ');
|
return timestamp.replace('T', ' ').replace('Z', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cleanBytesString = (bytes) => {
|
export const cleanBytesString = (bytes, decimals = 2) => {
|
||||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||||
if (!bytes || bytes === 0) {
|
if (!bytes || bytes === 0) {
|
||||||
return '0 B';
|
return '0 B';
|
||||||
}
|
}
|
||||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
|
const k = 1024;
|
||||||
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
|
const dm = decimals < 0 ? 0 : decimals;
|
||||||
|
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(k)));
|
||||||
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user