diff --git a/web/public/js/utils.js b/web/public/js/utils.js index 14aa2a54..4c7d63cc 100644 --- a/web/public/js/utils.js +++ b/web/public/js/utils.js @@ -140,27 +140,42 @@ window.teaweb = { } return (Math.round(bytes * 100 / Math.pow(1024, 6)) / 100) + "EB"; }, - formatBits: function (bits) { + formatBits: function (bits, decimal) { bits = Math.ceil(bits); + let div = 10000 + switch (decimal) { + case 1: + div = 10 + break + case 2: + div = 100 + break + case 3: + div = 1000 + break + case 4: + div = 10000 + break + } if (bits < Math.pow(1024, 1)) { return bits + "bps"; } if (bits < Math.pow(1024, 2)) { - return (Math.round(bits * 10000 / Math.pow(1024, 1)) / 10000) + "Kbps"; + return (Math.round(bits * div / Math.pow(1024, 1)) / div) + "Kbps"; } if (bits < Math.pow(1024, 3)) { - return (Math.round(bits * 10000 / Math.pow(1024, 2)) / 10000) + "Mbps"; + return (Math.round(bits * div / Math.pow(1024, 2)) / div) + "Mbps"; } if (bits < Math.pow(1024, 4)) { - return (Math.round(bits * 10000 / Math.pow(1024, 3)) / 10000) + "Gbps"; + return (Math.round(bits * div / Math.pow(1024, 3)) / div) + "Gbps"; } if (bits < Math.pow(1024, 5)) { - return (Math.round(bits * 10000 / Math.pow(1024, 4)) / 10000) + "Tbps"; + return (Math.round(bits * div / Math.pow(1024, 4)) / div) + "Tbps"; } if (bits < Math.pow(1024, 6)) { - return (Math.round(bits * 10000 / Math.pow(1024, 5)) / 10000) + "Pbps"; + return (Math.round(bits * div / Math.pow(1024, 5)) / div) + "Pbps"; } - return (Math.round(bits * 10000 / Math.pow(1024, 6)) / 10000) + "Ebps"; + return (Math.round(bits * div / Math.pow(1024, 6)) / div) + "Ebps"; }, formatNumber: function (x) { if (x == null) { diff --git a/web/views/@default/clusters/cluster/nodes.html b/web/views/@default/clusters/cluster/nodes.html index 3e02d599..fba18615 100644 --- a/web/views/@default/clusters/cluster/nodes.html +++ b/web/views/@default/clusters/cluster/nodes.html @@ -127,7 +127,7 @@ - - {{teaweb.formatBits(node.status.trafficOutBytes * 8/60)}} + {{teaweb.formatBits(node.status.trafficOutBytes * 8/60, 2)}} - diff --git a/web/views/@default/clusters/nodes.html b/web/views/@default/clusters/nodes.html index fe75e328..151f06aa 100644 --- a/web/views/@default/clusters/nodes.html +++ b/web/views/@default/clusters/nodes.html @@ -121,7 +121,7 @@ - - {{teaweb.formatBits(node.status.trafficOutBytes * 8/60)}} + {{teaweb.formatBits(node.status.trafficOutBytes * 8/60, 2)}} -