fixed 0 size display

This commit is contained in:
Djeeberjr 2021-09-02 18:36:56 +02:00
parent 61387e9fd8
commit cd20f098fa

View File

@ -1,4 +1,6 @@
function sizeToReadable(size: number): string { function sizeToReadable(size: number): string {
if (size == 0)
return "0 B"
const i = Math.floor(Math.log(size) / Math.log(1024)) const i = Math.floor(Math.log(size) / Math.log(1024))
const num = (size / Math.pow(1024, i)) const num = (size / Math.pow(1024, i))
return (num.toFixed(1).endsWith("0")?num.toFixed(0):num.toFixed(1)) + " " + ["B", "kB", "MB", "GB", "TB"][i] return (num.toFixed(1).endsWith("0")?num.toFixed(0):num.toFixed(1)) + " " + ["B", "kB", "MB", "GB", "TB"][i]