mirror of
https://github.com/optim-enterprises-bv/OptimCloud-gw-ui.git
synced 2025-10-29 17:32:20 +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', ' ');
|
||||
}
|
||||
|
||||
export const cleanBytesString = (bytes) => {
|
||||
export const cleanBytesString = (bytes, decimals = 2) => {
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
if (!bytes || bytes === 0) {
|
||||
return '0 B';
|
||||
}
|
||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
|
||||
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
|
||||
const k = 1024;
|
||||
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