From 37fb3bdbf827399250e84d28547b09a972930066 Mon Sep 17 00:00:00 2001 From: Henri Nieminen Date: Fri, 31 May 2024 10:06:28 +0300 Subject: [PATCH] change type for formatDecimalNumber to take in string --- src/util/helpers.tsx | 4 ++-- src/util/spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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', () => {