Skip to content

Commit

Permalink
change type for formatDecimalNumber to take in string
Browse files Browse the repository at this point in the history
  • Loading branch information
henrinie-nc committed May 31, 2024
1 parent 521b789 commit 37fb3bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/util/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/util/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 37fb3bd

Please sign in to comment.