@spa-tools/utilities
formatDollars()
The formatDollars()
function formats a number as a US dollar amount and is a shortcut
helper that wraps the formatMoney()
function.
Usage
import { formatDollars } from '@spa-tools/utilities';
const value1 = 1234.56;
const dollars1 = formatDollars(value1);
console.log(dollars1);
// --> $1,234.56
const value2 = 5678.901;
const dollars2 = formatDollars(value2, true, 3);
console.log(dollars2);
// --> 5,678.901
const value3 = 9012.3456;
const dollars3 = formatDollars(value3, false, 2);
console.log(dollars3);
// --> $9,012.35
Arguments
Name | Type | Required? | Default | Description |
---|---|---|---|---|
value | number | undefined | yes | - | The value to format |
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
.