From 0f6dff6315d82016dd2a93475acd14c75a6bc569 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Fri, 8 Dec 2017 23:39:33 -0500 Subject: [PATCH] Make value formatting consistent with GUI --- src/webui/www/public/scripts/misc.js | 11 +++++++---- src/webui/www/public/scripts/progressbar.js | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/webui/www/public/scripts/misc.js b/src/webui/www/public/scripts/misc.js index 6d60ef570..6d76837e1 100644 --- a/src/webui/www/public/scripts/misc.js +++ b/src/webui/www/public/scripts/misc.js @@ -30,9 +30,12 @@ function friendlyUnit(value, isSpeed) { var ret; if (i === 0) ret = value + " " + units[i]; - else - ret = (Math.floor(10 * value) / 10).toFixed(friendlyUnitPrecision(i)) //Don't round up - + " " + units[i]; + else { + var precision = friendlyUnitPrecision(i); + var offset = Math.pow(10, precision); + // Don't round up + ret = (Math.floor(offset * value) / offset).toFixed(precision) + " " + units[i]; + } if (isSpeed) ret += "QBT_TR(/s)QBT_TR[CONTEXT=misc]"; @@ -70,7 +73,7 @@ function friendlyPercentage(value) { percentage = 0; if (percentage > 100) percentage = 100; - return percentage + "%"; + return percentage.toFixed(1) + "%"; } /* diff --git a/src/webui/www/public/scripts/progressbar.js b/src/webui/www/public/scripts/progressbar.js index 880670ae8..de5edf68c 100644 --- a/src/webui/www/public/scripts/progressbar.js +++ b/src/webui/www/public/scripts/progressbar.js @@ -78,8 +78,8 @@ function ProgressBar_setValue(value) { this.vals.value = value; this.vals.dark.empty(); this.vals.light.empty(); - this.vals.dark.appendText(value + '%'); - this.vals.light.appendText(value + '%'); + this.vals.dark.appendText(value.round(1).toFixed(1) + '%'); + this.vals.light.appendText(value.round(1).toFixed(1) + '%'); var r = parseInt(this.vals.width * (value / 100)); this.vals.dark.setStyle('clip', 'rect(0,' + r + 'px,' + this.vals.height + 'px,0)'); this.vals.light.setStyle('clip', 'rect(0,' + this.vals.width + 'px,' + this.vals.height + 'px,' + r + 'px)');