diff --git a/src/util/helpers.tsx b/src/util/helpers.tsx index efb879c4e..448ca3c39 100644 --- a/src/util/helpers.tsx +++ b/src/util/helpers.tsx @@ -237,11 +237,11 @@ export const formatNumberWithThousandSeparator = (x: any, separator: string = ' /** * Format decimal number - * @param {number} x + * @param {string} x * @param {number} decimals * @returns {string} */ -export const formatDecimalNumber = (x: number | null | undefined, decimals: number | null | undefined = 2): string | null | undefined => !isEmptyValue(x) ? x.toFixed(decimals || undefined).toString().replace('.', ',') : null; +export const formatDecimalNumber = (x: string | null | undefined, decimals: number | null | undefined = 2): string | null | undefined => !isEmptyValue(x) ? parseFloat(x).toFixed(decimals || undefined).toString().replace('.', ',') : null; /** * Format number to show on UI diff --git a/src/util/spec.ts b/src/util/spec.ts index fe3c00bc2..e38280c38 100644 --- a/src/util/spec.ts +++ b/src/util/spec.ts @@ -564,8 +564,8 @@ describe('utils', () => { expect(formatNumberWithThousandSeparator('10000000,1234', '.')).to.deep.equal('10.000.000,1234'); }); it('should format decimal number', () => { - expect(formatDecimalNumber(10000000.1234)).to.deep.equal('10000000,12'); - expect(formatDecimalNumber(10000000)).to.deep.equal('10000000,00'); + expect(formatDecimalNumber('10000000.1234')).to.deep.equal('10000000,12'); + expect(formatDecimalNumber('10000000')).to.deep.equal('10000000,00'); expect(formatDecimalNumber(null)).to.deep.equal(null); }); it('should format number', () => {