From e651b8c6411db5505e4e498a448626d20d146adc Mon Sep 17 00:00:00 2001 From: Mihail Slobodyanuk Date: Fri, 23 Dec 2022 16:37:21 +0200 Subject: [PATCH] Fix speed meterRIVM-47 --- contrib/ui/mesh-ui/ui/assets/mesh-ui.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/ui/mesh-ui/ui/assets/mesh-ui.js b/contrib/ui/mesh-ui/ui/assets/mesh-ui.js index 36b84cd4..4b914300 100644 --- a/contrib/ui/mesh-ui/ui/assets/mesh-ui.js +++ b/contrib/ui/mesh-ui/ui/assets/mesh-ui.js @@ -227,7 +227,13 @@ function togglePrivKeyVisibility() { function humanReadableSpeed(speed) { if (speed < 0) return "? B/s"; var i = speed < 1 ? 0 : Math.floor(Math.log(speed) / Math.log(1024)); - return (speed / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B/s', 'kB/s', 'MB/s', 'GB/s', 'TB/s'][i]; + var val = speed / Math.pow(1024, i); + var fixed = 2; + if((val.toFixed() * 1) > 9) { + fixed = 1; + val = val / 10 + } + return val.toFixed(fixed) * 1 + ' ' + ['B/s', 'kB/s', 'MB/s', 'GB/s', 'TB/s'][i]; } var ui = ui || {