You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
307 B
12 lines
307 B
const formatDollars = amount => {
|
|
const units = [[1e12, 'T'], [1e9, 'B'], [1e6, 'M']];
|
|
for (const [devisor, suffix] of units) {
|
|
if (amount >= devisor) {
|
|
return `$${(amount / devisor).toFixed(2)} ${suffix}`;
|
|
}
|
|
}
|
|
|
|
return `$${Math.floor(amount).toLocaleString()}`;
|
|
};
|
|
|
|
export default formatDollars;
|
|
|