diff --git a/components/statistic/Number.tsx b/components/statistic/Number.tsx index 6d6e0bd062..0e9fc2222f 100644 --- a/components/statistic/Number.tsx +++ b/components/statistic/Number.tsx @@ -30,7 +30,7 @@ const StatisticNumber: React.FC = props => { int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator); if (typeof precision === 'number') { - decimal = padEnd(decimal, precision, '0').slice(0, precision); + decimal = padEnd(decimal, precision, '0').slice(0, precision > 0 ? precision : 0); } if (decimal) { diff --git a/components/statistic/__tests__/index.test.js b/components/statistic/__tests__/index.test.js index 109df17ab2..abd47d69d8 100644 --- a/components/statistic/__tests__/index.test.js +++ b/components/statistic/__tests__/index.test.js @@ -51,6 +51,20 @@ describe('Statistic', () => { expect(wrapper.render()).toMatchSnapshot(); }); + it('allow negetive precision', () => { + [ + [-1, -1112893.1212, '-1,112,893'], + [-2, -1112893.1212, '-1,112,893'], + [-3, -1112893.1212, '-1,112,893'], + [-1, -1112893, '-1,112,893'], + [-1, 1112893, '1,112,893'], + ].forEach(([precision, value, expectValue]) => { + const wrapper = mount(); + expect(wrapper.find('.ant-statistic-content-value-int').text()).toEqual(expectValue); + expect(wrapper.find('.ant-statistic-content-value-decimal').length).toBe(0); + }) + }); + it('loading with skeleton', async () => { let loading = false; const wrapper = mount();