gab-social/app/javascript/gabsocial/utils/numbers.js

19 lines
425 B
JavaScript
Raw Normal View History

2020-02-08 06:12:01 +00:00
import { Fragment } from 'react'
import { FormattedNumber } from 'react-intl'
2019-07-02 08:10:25 +01:00
2020-04-29 03:24:35 +01:00
export const shortNumberFormat = (number) => {
2019-07-02 08:10:25 +01:00
if (number < 1000) {
2020-04-29 03:24:35 +01:00
try {
return (<FormattedNumber value={number} />).props.value
} catch (error) {
return <FormattedNumber value={number} />
}
2019-07-02 08:10:25 +01:00
}
2020-02-08 06:12:01 +00:00
return (
<Fragment>
<FormattedNumber value={number / 1000} maximumFractionDigits={1} />k
2020-02-08 06:12:01 +00:00
</Fragment>
)
}