From 833c1d4fca199800705ac76b1ee9d57aa63cacf1 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 10 Dec 2015 10:54:44 +0100 Subject: [PATCH] respect precision of float metrics during web formatting --- .../sonar-web/src/main/js/helpers/measures.js | 4 ++-- .../sonar-web/tests/helpers/measures-test.js | 24 +++++++++++++++---- 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 () { -- 2.39.5