diff --git a/src/libs/CurrencyUtils.ts b/src/libs/CurrencyUtils.ts index 862b0ae5e928..c3b80797d750 100644 --- a/src/libs/CurrencyUtils.ts +++ b/src/libs/CurrencyUtils.ts @@ -125,9 +125,11 @@ function convertToDisplayString(amountInCents = 0, currency: string = CONST.CURR style: 'currency', currency: currencyWithFallback, - // We are forcing the number of decimals because we override the default number of decimals in the backend for RSD + // We are forcing the number of decimals because we override the default number of decimals in the backend for some currencies // See: https://github.com/Expensify/PHP-Libs/pull/834 - minimumFractionDigits: currency === 'RSD' ? getCurrencyDecimals(currency) : undefined, + minimumFractionDigits: getCurrencyDecimals(currency), + // For currencies that have decimal places > 2, floor to 2 instead as we don't support more than 2 decimal places. + maximumFractionDigits: 2, }); } @@ -175,9 +177,11 @@ function convertToDisplayStringWithoutCurrency(amountInCents: number, currency: style: 'currency', currency, - // We are forcing the number of decimals because we override the default number of decimals in the backend for RSD + // We are forcing the number of decimals because we override the default number of decimals in the backend for some currencies // See: https://github.com/Expensify/PHP-Libs/pull/834 - minimumFractionDigits: currency === 'RSD' ? getCurrencyDecimals(currency) : undefined, + minimumFractionDigits: getCurrencyDecimals(currency), + // For currencies that have decimal places > 2, floor to 2 instead as we don't support more than 2 decimal places. + maximumFractionDigits: 2, }) .filter((x) => x.type !== 'currency') .filter((x) => x.type !== 'literal' || x.value.trim().length !== 0) diff --git a/tests/unit/CurrencyUtilsTest.ts b/tests/unit/CurrencyUtilsTest.ts index 5322faff763f..9a86c9188d42 100644 --- a/tests/unit/CurrencyUtilsTest.ts +++ b/tests/unit/CurrencyUtilsTest.ts @@ -155,8 +155,8 @@ describe('CurrencyUtils', () => { ['JPY', 2500.5, '¥25'], ['RSD', 100, 'RSD\xa01.00'], ['RSD', 145, 'RSD\xa01.45'], - ['BHD', 12345, 'BHD\xa0123.450'], - ['BHD', 1, 'BHD\xa00.010'], + ['BHD', 12345, 'BHD\xa0123.45'], + ['BHD', 1, 'BHD\xa00.01'], ])('Correctly displays %s', (currency, amount, expectedResult) => { expect(CurrencyUtils.convertToDisplayString(amount, currency)).toBe(expectedResult); });