refs #5667 Fix decimal places
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2023-05-17 13:02:51 +02:00
parent 0d51987d47
commit e7f9984b4b
2 changed files with 20 additions and 0 deletions

View File

@ -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';

View File

@ -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');
});
});
});