From e7f9984b4b061a23127f5ae8e911a11a179cb011 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 17 May 2023 13:02:51 +0200 Subject: [PATCH] refs #5667 Fix decimal places --- front/core/components/json-value/index.js | 6 ++++++ front/core/components/json-value/index.spec.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/front/core/components/json-value/index.js b/front/core/components/json-value/index.js index 226bf8477..6b7517417 100644 --- a/front/core/components/json-value/index.js +++ b/front/core/components/json-value/index.js @@ -28,6 +28,12 @@ export default class Controller extends Component { } else { cssClass = type; switch (type) { + case 'number': + if (Number.isInteger(value)) + text = value; + else + text = Math.round((value + Number.EPSILON) * 1000) / 1000; + break; case 'boolean': text = value ? '✓' : '✗'; cssClass = value ? 'true' : 'false'; diff --git a/front/core/components/json-value/index.spec.js b/front/core/components/json-value/index.spec.js index b79d15a5d..ff7a45977 100644 --- a/front/core/components/json-value/index.spec.js +++ b/front/core/components/json-value/index.spec.js @@ -75,5 +75,19 @@ describe('Component vnJsonValue', () => { expect(el.textContent).toEqual('2050'); expect(el.className).toContain('json-number'); }); + + it('should display number when value is decimal', () => { + controller.value = 10.1; + + expect(el.textContent).toEqual('10.1'); + expect(el.className).toContain('json-number'); + }); + + it('should display rounded number when value is decimal with lot of decimals', () => { + controller.value = 10.124323234; + + expect(el.textContent).toEqual('10.124'); + expect(el.className).toContain('json-number'); + }); }); });