@spa-tools/utilities
formatMoney()
The formatMoney()
function formats a number as a currency amount.
Usage
import { formatMoney } from '@spa-tools/utilities';
const money1 = formatMoney(123456.789, 'USD');
console.log(money1);
// --> $123,456.79
const money2 = formatMoney(123456.789, 'EUR', false, 3);
console.log(money2);
// --> 123,456.789 €
const money3 = formatMoney(123456.789, 'USD', true);
console.log(money3);
// --> 123,456.79
Arguments
Name | Type | Required? | Default | Description |
---|---|---|---|---|
value | number | undefined | yes | - | The value to format |
currency | string | yes | - | The currency format to use |
excludeSymbol | boolean | no | false | Determines whether or not to exclude the dollar sign |
decimalPlaces | number | no | 2 | The number of decimal places to round to |
Returns
Returns formatted dollars or ''
if value
is undefined
.