Skip to content

fix(i18n): honor the requested currency in formatCurrency - #975

Merged
thlpkee20-wq merged 2 commits into
RevoraOrg:masterfrom
temisan0x:fix/920-format-currency-ignores-currency
Oct 22, 2026
Merged

thlpkee20-wq merged 2 commits into
RevoraOrg:masterfrom
temisan0x:fix/920-format-currency-ignores-currency

Conversation

@temisan0x

Copy link
Copy Markdown

Closes #920

What was broken

formatCurrency(value, currency, locale) spread the locale's currency settings over the options after setting the requested currency, so the locale's own currency won. formatCurrency(100, 'USD', 'de-DE') rendered euros, and the ja-JP settings also forced 0 decimals on every currency.

What this changes

  • The resolved currency is now applied after the locale settings, so an explicit currency argument always wins. The locale's defaultCurrency only applies when no currency is passed.
  • Removed currency and maximumFractionDigits from the 8 locale currency settings objects. defaultCurrency already covers the default, and Intl picks the right decimals per currency.
  • Renamed the local defaultCurr variable to resolvedCurrency, since it holds the requested currency, not just the default.
  • Explicit non-default currencies now use Intl's own decimals instead of the locale's: for example KWD and BHD show 3 decimals, KRW shows 0, and USD in ja-JP shows 2. Each locale's default currency renders exactly as before; I compared old and new output for all 8 locales.

Caller audit

Only RevenueReportForm, RevenueReportingCalendar and I18nFormatterPreview use this helper. The first two pass an explicit currency with a locale, which is the path this fixes. The preview passes no currency, so it is unaffected. The other formatCurrency functions in the codebase are local to their own components and don't use this one.

Tests

Added to src/constants/i18n.test.ts:

  • a requested currency wins over the locale default (USD in de-DE shows $, EUR in en-US shows €, GBP in ja-JP matches Intl)
  • no currency falls back to the locale default (de-DE gives EUR, ja-JP gives JPY)
  • decimals drop only when JPY is requested (USD in ja-JP keeps cents)

Two of these fail on current master (100,00 € instead of a dollar amount, and $1,234.50 for JPY) and pass with the fix.

Notes

  • 38 tests in RevenueReportingCalendar.test.tsx and I18nFormatterPreview/index.test.tsx fail on this branch. I ran the same suites on a clean master and got the same failures, so they are not caused by this change. The preview failure is a RangeError from formatNumber on an invalid locale.
  • tsc --noEmit currently fails on master because of parse errors in TwoFactorSetup.test.tsx. This PR adds no type errors.

@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@temisan0x Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(i18n): formatCurrency ignores the requested currency and formats amounts in the locale's default currency

2 participants