Skip to content

Commit

Permalink
fix(number): needed to fix fraction digits
Browse files Browse the repository at this point in the history
  • Loading branch information
hirsch88 committed Sep 11, 2023
1 parent 703eda0 commit 81cf276
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/utils/src/utils/number.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('number', () => {

describe('formatLocaleNumber', () => {
test('should format the number into the given locale', () => {
expect(formatLocaleNumber('de-CH', 1000.4231, 2)).toBe('1’000.42')
expect(formatLocaleNumber('de-CH', 1000.42)).toBe('1’000.42')
expect(formatLocaleNumber('de-DE', 1000.42)).toBe('1.000,42')
expect(formatLocaleNumber('de-DE', 0)).toBe('0')
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export function getThousandSeparator(locale = 'de-CH'): string {
* ```
*/
export function formatLocaleNumber(locale = 'de-CH', number: number, minimumFractionDigits?: number): string {
const options = minimumFractionDigits !== undefined ? { minimumFractionDigits } : {}
const options =
minimumFractionDigits !== undefined ? { minimumFractionDigits, maximumFractionDigits: minimumFractionDigits } : {}
const formattedNumber = Intl.NumberFormat(numberLocale(locale), {
...options,
}).format(number)
Expand Down

0 comments on commit 81cf276

Please sign in to comment.