How to use the i18n-js.toCurrency function in i18n-js

To help you get started, we’ve selected a few i18n-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sage / carbon / src / utils / helpers / i18n / i18n.js View on Github external
formatCurrency: (valueToFormat = 0, options = {}) => {
    const locale = options.locale || I18n.locale || 'en';
    const format = I18nHelper.format(locale);
    let { precision } = options;
    const unit = options.unit || format.unit;
    const structure = options.format || format.format;

    // Checking explicitly as 0 is a valid precision
    if (typeof precision === 'undefined' || precision === null) {
      precision = 2;
    }

    return I18n.toCurrency(valueToFormat, {
      precision,
      delimiter: format.delimiter,
      separator: format.separator,
      unit,
      format: structure
    });
  },