From 98ebb2b7894c6d221c7efca4691ac8388349320e Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 26 Jun 2024 03:32:32 +0530 Subject: [PATCH 1/4] fix: IOU - On entering amount with decimals, 3rd decimal 0 is added in IOU confirmation page. Signed-off-by: Krishna Gupta --- src/libs/CurrencyUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/CurrencyUtils.ts b/src/libs/CurrencyUtils.ts index 7b54fbf0bed7..62a1e7f69bfa 100644 --- a/src/libs/CurrencyUtils.ts +++ b/src/libs/CurrencyUtils.ts @@ -126,6 +126,7 @@ function convertToDisplayString(amountInCents = 0, currency: string = CONST.CURR // We are forcing the number of decimals because we override the default number of decimals in the backend for RSD // See: https://github.com/Expensify/PHP-Libs/pull/834 minimumFractionDigits: currency === 'RSD' ? getCurrencyDecimals(currency) : undefined, + maximumFractionDigits: 2, }); } From d8054b9a6315d176280524ae934c146cbd4a15d9 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 26 Jun 2024 04:40:34 +0530 Subject: [PATCH 2/4] fix for android native. Signed-off-by: Krishna Gupta --- src/libs/CurrencyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/CurrencyUtils.ts b/src/libs/CurrencyUtils.ts index 62a1e7f69bfa..28747a472dbd 100644 --- a/src/libs/CurrencyUtils.ts +++ b/src/libs/CurrencyUtils.ts @@ -125,7 +125,7 @@ function convertToDisplayString(amountInCents = 0, currency: string = CONST.CURR // We are forcing the number of decimals because we override the default number of decimals in the backend for RSD // See: https://github.com/Expensify/PHP-Libs/pull/834 - minimumFractionDigits: currency === 'RSD' ? getCurrencyDecimals(currency) : undefined, + minimumFractionDigits: currency === 'RSD' ? getCurrencyDecimals(currency) : 0, maximumFractionDigits: 2, }); } From 96d38dee30966a80526849f12b8cf8bbf798eeac Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 26 Jun 2024 04:43:36 +0530 Subject: [PATCH 3/4] fix for android native. Signed-off-by: Krishna Gupta --- src/libs/CurrencyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/CurrencyUtils.ts b/src/libs/CurrencyUtils.ts index 28747a472dbd..3d037b313c08 100644 --- a/src/libs/CurrencyUtils.ts +++ b/src/libs/CurrencyUtils.ts @@ -125,7 +125,7 @@ function convertToDisplayString(amountInCents = 0, currency: string = CONST.CURR // We are forcing the number of decimals because we override the default number of decimals in the backend for RSD // See: https://github.com/Expensify/PHP-Libs/pull/834 - minimumFractionDigits: currency === 'RSD' ? getCurrencyDecimals(currency) : 0, + minimumFractionDigits: getCurrencyDecimals(currency), maximumFractionDigits: 2, }); } From 0747007ea1e1daa9f396a28135552a886c27e6d0 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Wed, 10 Jul 2024 04:50:49 +0530 Subject: [PATCH 4/4] fix tests. Signed-off-by: krishna2323 --- src/libs/CurrencyUtils.ts | 9 ++++++--- tests/unit/CurrencyUtilsTest.ts | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libs/CurrencyUtils.ts b/src/libs/CurrencyUtils.ts index 6a45ac1f2d01..c3b80797d750 100644 --- a/src/libs/CurrencyUtils.ts +++ b/src/libs/CurrencyUtils.ts @@ -125,9 +125,10 @@ 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: 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, }); } @@ -176,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); });