-
Notifications
You must be signed in to change notification settings - Fork 0
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.
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.
The function takes the following arguments:
-
amountis 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.
-
countryis not used currently. The default:'US'.
The return is a string, which contains a presentable currency information.
const currency = formatCurrency(Math.PI);
assert(currency === '$3.14');
const debt = formatCurrency(1234567.89012345);
assert(currency === '$1,234,567.89');