From c3175d3e65a5617bd8a1dca3df7f895f1ce9d027 Mon Sep 17 00:00:00 2001 From: Dexter Edwards Date: Fri, 21 Oct 2022 16:30:30 +0100 Subject: [PATCH] fix: do no allow min or max fraction digits to go out of range (#1806) (#1809) --- libs/react-helpers/src/lib/format/number.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/react-helpers/src/lib/format/number.tsx b/libs/react-helpers/src/lib/format/number.tsx index 2c93b8279..95dba74c0 100644 --- a/libs/react-helpers/src/lib/format/number.tsx +++ b/libs/react-helpers/src/lib/format/number.tsx @@ -5,6 +5,8 @@ import memoize from 'lodash/memoize'; import React from 'react'; import { getUserLocale } from './utils'; +const MAX_FRACTION_DIGITS = 20; + export function toDecimal(numberOfDecimals: number) { return 1 / Math.pow(10, numberOfDecimals); } @@ -41,8 +43,8 @@ export const getNumberFormat = memoize((digits: number) => { return new Intl.NumberFormat(getUserLocale()); } return new Intl.NumberFormat(getUserLocale(), { - minimumFractionDigits: Math.max(0, digits), - maximumFractionDigits: Math.max(0, digits), + minimumFractionDigits: Math.min(Math.max(0, digits), MAX_FRACTION_DIGITS), + maximumFractionDigits: Math.min(Math.max(0, digits), MAX_FRACTION_DIGITS), }); });