Skip to main content
@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

NameTypeRequired?DefaultDescription
valuenumber | undefinedyes-The value to format
currencystringyes-The currency format to use
excludeSymbolbooleannofalseDetermines whether or not to exclude the dollar sign
decimalPlacesnumberno2The number of decimal places to round to

Returns

Returns formatted dollars or '' if value is undefined.