Commit e16a51ad by Torkel Ödegaard

Singlestat: fixed decimal precision bug, #951

parent 6861dc13
...@@ -327,20 +327,18 @@ function($, _, moment) { ...@@ -327,20 +327,18 @@ function($, _, moment) {
size /= factor; size /= factor;
} }
if (steps > 0) { if (steps > 0) {
scaledDecimals = scaledDecimals + (3 * steps); decimals = scaledDecimals + (3 * steps);
} }
return kbn.toFixed(size, scaledDecimals, decimals) + extArray[steps]; return kbn.toFixed(size, decimals) + extArray[steps];
}; };
}; };
kbn.toFixed = function(value, decimals, fallbackDecimals) { kbn.toFixed = function(value, decimals) {
if (value === null) { if (value === null) {
return ""; return "";
} }
decimals = decimals || fallbackDecimals;
var factor = decimals ? Math.pow(10, decimals) : 1; var factor = decimals ? Math.pow(10, decimals) : 1;
var formatted = String(Math.round(value * factor) / factor); var formatted = String(Math.round(value * factor) / factor);
......
...@@ -166,6 +166,8 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -166,6 +166,8 @@ function (angular, app, _, TimeSeries, kbn) {
var result = {}; var result = {};
result.decimals = Math.max(0, dec); result.decimals = Math.max(0, dec);
result.scaledDecimals = result.decimals - Math.floor(Math.log(size) / Math.LN10); result.scaledDecimals = result.decimals - Math.floor(Math.log(size) / Math.LN10);
console.log(result);
return result; return result;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment