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

NameTypeRequired?DefaultDescription
valuenumber | undefinedyes-The value to format
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.