Skip to content

Library: formatCurrency()

Eugene Lazutkin edited this page Jul 3, 2018 · 3 revisions

formatCurrency() module is a function, which formats a number as a currency value. Right now only the US option is supported.

Usage

In a module-enabled environment (like Babel) it can be accessed like that:

import formatCurrency from '@researchnow/reno/src/utils/formatCurrency';

In global-based environments (like a browser) it is frequently mapped to Reno.utils.formatCurrency.

formatCurrency(amount, country='US')

The function takes the following arguments:

  • amount is a number. It will be rounded up to a precision according to a country-specific information. Then it will be formatted using an appropriate currency symbol.
    • A number is formatted by formatNumber() to insert proper fractional and millennia separators.
  • country is not used currently. The default: 'US'.

The return is a string, which contains a presentable currency information.

Examples

const currency = formatCurrency(Math.PI);
assert(currency === '$3.14');

const debt = formatCurrency(1234567.89012345);
assert(currency === '$1,234,567.89');

Clone this wiki locally