]> source.dussan.org Git - sonarqube.git/commitdiff
respect precision of float metrics during web formatting
authorStas Vilchik <vilchiks@gmail.com>
Thu, 10 Dec 2015 09:54:44 +0000 (10:54 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Thu, 10 Dec 2015 09:54:44 +0000 (10:54 +0100)
server/sonar-web/src/main/js/helpers/measures.js
server/sonar-web/tests/helpers/measures-test.js

index 2137e40c6b80bef8f14588682cc1c0766c77f458..ffb6e576152e8edc7fccec505f582659031ebbe0 100644 (file)
@@ -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) {
index cc8e7a4a25c5721027feb5512e235c57cdb1495a..2caabb3cdf579cae50c1cd1cfb324b8de5c7e3bd 100644 (file)
@@ -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 () {