Skip to content

Commit

Permalink
Merge pull request #44416 from Krishna2323/krishna2323/issue/43945
Browse files Browse the repository at this point in the history
fix: IOU - On entering amount with decimals, 3rd decimal 0 is added in IOU confirmation page.
  • Loading branch information
thienlnam authored Jul 10, 2024
2 parents 3e8411a + 0747007 commit 2b2a2e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/libs/CurrencyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/CurrencyUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 2b2a2e0

Please sign in to comment.