Display currency for any locale

  1. SDK Version: 37
  2. Platforms(Android/iOS/web/all): Android

In the scenario where we want to display a money amount for a specific currency/locale, the function Intl.NumberFormat is the way to go.

Unfortunately for Android, this doesn’t work (anymore). It could be done with a polyfill, but that only works if you know the locale beforehand.

There is a workaround by adding a more recent JSC for Android, but I think this is not possible with the managed Expo?

It’s great we have access to Localization.locale, but it would be even better if we can actually use it to format currencies.

Possible solutions:

  • Allow defining a more recent (or international) version of JSC (for Android) for our builds.
  • Include a more recent (or international) version of JSC by default in Expo.
2 Likes

My workaround for now:

import currencyFormatter from 'currency-formatter';
import * as Localization from 'expo-localization';

// Android doesn't support Intl currently, for now this workaround.
const formatCurrency = (amount, currencyCode, locale=Localization.locale) => {
    try {
        return new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode }).format(amount);
    } catch (error) {
        if (locale == 'en-NL') locale = 'nl-NL'; // bugfix
        return currencyFormatter.format(amount, { locale: locale, code: currencyCode });
    }
}

export default formatCurrency;

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.