opnsense/core: fix file size suffix (#3379)

This commit is contained in:
Fabian Franz BSc 2019-03-31 00:06:39 +01:00 committed by Ad Schellevis
parent cec76910b4
commit e43e8edab6

View File

@ -41,7 +41,7 @@
decimals = 0;
}
const kb = 1024;
const ndx = Math.floor(Math.log(bytes) / Math.log(kb));
const ndx = bytes === 0 ? 0 : Math.floor(Math.log(bytes) / Math.log(kb));
const fileSizeTypes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
return (bytes / Math.pow(kb, ndx)).toFixed(decimals) + ' ' + fileSizeTypes[ndx];
}