change to 0 KB if bytes == 0
parent
0c55303505
commit
166ba54c4b
|
@ -1,5 +1,8 @@
|
|||
export default function dataConversion(bytes: number) {
|
||||
export default function dataConversion(bytes) {
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
if (bytes === 0) {
|
||||
return '0 KB';
|
||||
}
|
||||
return `${(bytes / 1024 ** i).toFixed(2)} ${sizes[i]}`;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue