mirror of https://github.com/zulip/zulip.git
stats.js: Change how we set the precision for percentages close to 100%.
This commit is contained in:
parent
5f7cb9db16
commit
9901128b33
|
@ -303,13 +303,8 @@ function round_percentages(values) {
|
|||
var total = values.reduce(function (a, b) { return a + b; }, 0);
|
||||
var percents = values.map(function (x) {
|
||||
var unrounded = x/total*100;
|
||||
var rounded;
|
||||
if (unrounded > 99.4) {
|
||||
rounded = unrounded.toPrecision(3);
|
||||
} else {
|
||||
rounded = unrounded.toPrecision(2);
|
||||
}
|
||||
return rounded + '%';
|
||||
var precision = Math.max(2, Math.floor(-Math.log(100-unrounded)/Math.log(10)) + 3);
|
||||
return unrounded.toPrecision(precision) + '%';
|
||||
});
|
||||
return [total, percents];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue