Update dollars filter and formatDollars() to display cent values

This commit is contained in:
leigh-mil
2019-01-31 11:29:52 -05:00
parent 6d61839c65
commit 0382966929
3 changed files with 9 additions and 17 deletions

View File

@@ -1,8 +1,9 @@
export const formatDollars = (value, cents = true) => {
if (typeof value === 'number') {
return cents
? `$${value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}`
: `$${value.toFixed(0).replace(/\d(?=(\d{3})+(?!\d))/g, '$&,')}`
return value.toLocaleString('us-US', {
style: 'currency',
currency: 'USD',
})
}
return ''
}