aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-12-10 10:54:44 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-12-10 10:54:44 +0100
commit833c1d4fca199800705ac76b1ee9d57aa63cacf1 (patch)
tree5d013e9048897efd7e7f865be29b44a08afc590e
parent4904c052b4e5f7ed0e061655a6b1a8a3e4f8e2ad (diff)
downloadsonarqube-833c1d4fca199800705ac76b1ee9d57aa63cacf1.tar.gz
sonarqube-833c1d4fca199800705ac76b1ee9d57aa63cacf1.zip
respect precision of float metrics during web formatting
-rw-r--r--server/sonar-web/src/main/js/helpers/measures.js4
-rw-r--r--server/sonar-web/tests/helpers/measures-test.js24
2 files changed, 21 insertions, 7 deletions
diff --git a/server/sonar-web/src/main/js/helpers/measures.js b/server/sonar-web/src/main/js/helpers/measures.js
index 2137e40c6b8..ffb6e576152 100644
--- a/server/sonar-web/src/main/js/helpers/measures.js
+++ b/server/sonar-web/src/main/js/helpers/measures.js
@@ -125,11 +125,11 @@ function shortIntVariationFormatter (value) {
}
function floatFormatter (value) {
- return numeral(value).format('0,0.0');
+ return numeral(value).format('0,0.0[0000]');
}
function floatVariationFormatter (value) {
- return value === 0 ? '+0.0' : numeral(value).format('+0,0.0');
+ return value === 0 ? '+0.0' : numeral(value).format('+0,0.0[0000]');
}
function percentFormatter (value) {
diff --git a/server/sonar-web/tests/helpers/measures-test.js b/server/sonar-web/tests/helpers/measures-test.js
index cc8e7a4a25c..2caabb3cdf5 100644
--- a/server/sonar-web/tests/helpers/measures-test.js
+++ b/server/sonar-web/tests/helpers/measures-test.js
@@ -68,14 +68,21 @@ describe('Measures', function () {
expect(formatMeasure(0.0, 'FLOAT')).to.equal('0.0');
expect(formatMeasure(1.0, 'FLOAT')).to.equal('1.0');
expect(formatMeasure(1.3, 'FLOAT')).to.equal('1.3');
- expect(formatMeasure(1.34, 'FLOAT')).to.equal('1.3');
- expect(formatMeasure(50.89, 'FLOAT')).to.equal('50.9');
+ expect(formatMeasure(1.34, 'FLOAT')).to.equal('1.34');
+ expect(formatMeasure(50.89, 'FLOAT')).to.equal('50.89');
expect(formatMeasure(100.0, 'FLOAT')).to.equal('100.0');
- expect(formatMeasure(123.456, 'FLOAT')).to.equal('123.5');
+ expect(formatMeasure(123.456, 'FLOAT')).to.equal('123.456');
expect(formatMeasure(123456.7, 'FLOAT')).to.equal('123,456.7');
expect(formatMeasure(1234567890.0, 'FLOAT')).to.equal('1,234,567,890.0');
});
+ it('should respect FLOAT precision', function () {
+ expect(formatMeasure(0.1, 'FLOAT')).to.equal('0.1');
+ expect(formatMeasure(0.12, 'FLOAT')).to.equal('0.12');
+ expect(formatMeasure(0.12345, 'FLOAT')).to.equal('0.12345');
+ expect(formatMeasure(0.123456, 'FLOAT')).to.equal('0.12346');
+ });
+
it('should format PERCENT', function () {
expect(formatMeasure(0.0, 'PERCENT')).to.equal('0.0%');
expect(formatMeasure(1.0, 'PERCENT')).to.equal('1.0%');
@@ -180,8 +187,15 @@ describe('Measures', function () {
expect(formatMeasureVariation(0.0, 'FLOAT')).to.equal('+0.0');
expect(formatMeasureVariation(1.0, 'FLOAT')).to.equal('+1.0');
expect(formatMeasureVariation(-1.0, 'FLOAT')).to.equal('-1.0');
- expect(formatMeasureVariation(50.89, 'FLOAT')).to.equal('+50.9');
- expect(formatMeasureVariation(-50.89, 'FLOAT')).to.equal('-50.9');
+ expect(formatMeasureVariation(50.89, 'FLOAT')).to.equal('+50.89');
+ expect(formatMeasureVariation(-50.89, 'FLOAT')).to.equal('-50.89');
+ });
+
+ it('should respect FLOAT precision', function () {
+ expect(formatMeasureVariation(0.1, 'FLOAT')).to.equal('+0.1');
+ expect(formatMeasureVariation(0.12, 'FLOAT')).to.equal('+0.12');
+ expect(formatMeasureVariation(0.12345, 'FLOAT')).to.equal('+0.12345');
+ expect(formatMeasureVariation(0.123456, 'FLOAT')).to.equal('+0.12346');
});
it('should format PERCENT', function () {