fix(05): slip file display

This commit is contained in:
puriphatt 2024-10-21 14:04:21 +07:00
parent 8d87368a7c
commit 2abdc093a1
2 changed files with 25 additions and 8 deletions

View file

@ -445,4 +445,17 @@ export function commaInput(text: string): string {
return integerPart + (decimalPart ? `.${decimalPart}` : '');
}
export function convertFileSize(size: number): string {
if (size === undefined) return 'Unknow size';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let i = 0;
let sizeNumber = typeof size === 'string' ? parseFloat(size) : size;
while (sizeNumber >= 1024 && i++ < units.length - 1) {
sizeNumber /= 1024;
}
return sizeNumber.toFixed(2) + ' ' + units[i];
}
export default useUtilsStore;