Add type checking on formatDollars
add param to hide cents
This commit is contained in:
parent
221836c8cf
commit
24acfb5010
@ -1,4 +1,11 @@
|
||||
export const formatDollars = value => `$${value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}`
|
||||
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}))/g, '$&,')}`
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
export const abbreviateDollars = (value, decimals = 1) => {
|
||||
if (value === null) { return null } // terminate early
|
||||
|
Loading…
x
Reference in New Issue
Block a user