Updated numbers util to truncate MILLIONS (!)

• Updated:
- numbers util to truncate MILLIONS
This commit is contained in:
mgabdev 2021-01-09 20:39:59 -05:00
parent f873a1f925
commit 60ce67309c
1 changed files with 5 additions and 1 deletions

View File

@ -14,9 +14,13 @@ export const shortNumberFormat = (number) => {
} }
} }
const isMillions = number > 999999
const isThousands = number > 999 && !isMillions
const divisor = isMillions ? 1000000 : isThousands ? 1000 : 1
const suffix = isMillions ? 'm' : isThousands ? 'k' : ''
return ( return (
<React.Fragment> <React.Fragment>
<FormattedNumber value={number / 1000} maximumFractionDigits={1} />k <FormattedNumber value={number / divisor} maximumFractionDigits={1} />{suffix}
</React.Fragment> </React.Fragment>
) )
} }