diff --git a/web/assets/js/util/index.js b/web/assets/js/util/index.js index e69f3341..039b5368 100644 --- a/web/assets/js/util/index.js +++ b/web/assets/js/util/index.js @@ -591,6 +591,16 @@ class SizeFormatter { if (size < this.ONE_PB) return (size / this.ONE_TB).toFixed(2) + " TB"; return (size / this.ONE_PB).toFixed(2) + " PB"; } + + static bitFormat(size) { + const bits = size * 8; + if (bits <= 0) return "0 b"; + if (bits < 1000) return bits.toFixed(0) + " b"; + if (bits < 1000000) return (bits / 1000).toFixed(2) + " Kb"; + if (bits < 1000000000) return (bits / 1000000).toFixed(2) + " Mb"; + if (bits < 1000000000000) return (bits / 1000000000).toFixed(2) + " Gb"; + return (bits / 1000000000000).toFixed(2) + " Tb"; + } } class CPUFormatter { diff --git a/web/html/index.html b/web/html/index.html index bbbbb708..ebd0becb 100644 --- a/web/html/index.html +++ b/web/html/index.html @@ -205,7 +205,7 @@ + :value="SizeFormatter.bitFormat(status.netIO.up)"> @@ -216,7 +216,7 @@ + :value="SizeFormatter.bitFormat(status.netIO.down)">