2020-08-17 15:07:16 -05:00
|
|
|
import React from 'react'
|
2020-02-08 01:12:01 -05:00
|
|
|
import { FormattedNumber } from 'react-intl'
|
2019-07-02 03:10:25 -04:00
|
|
|
|
2020-04-28 22:24:35 -04:00
|
|
|
export const shortNumberFormat = (number) => {
|
2020-12-02 23:22:51 -05:00
|
|
|
if (isNaN(number)) {
|
|
|
|
return <FormattedNumber value={0} />
|
|
|
|
}
|
|
|
|
|
2019-07-02 03:10:25 -04:00
|
|
|
if (number < 1000) {
|
2020-04-28 22:24:35 -04:00
|
|
|
try {
|
|
|
|
return (<FormattedNumber value={number} />).props.value
|
|
|
|
} catch (error) {
|
2020-12-02 23:22:51 -05:00
|
|
|
return <FormattedNumber value={0} />
|
2020-04-28 22:24:35 -04:00
|
|
|
}
|
2019-07-02 03:10:25 -04:00
|
|
|
}
|
2020-01-29 16:53:33 -05:00
|
|
|
|
2021-01-09 20:39:59 -05:00
|
|
|
const isMillions = number > 999999
|
|
|
|
const isThousands = number > 999 && !isMillions
|
|
|
|
const divisor = isMillions ? 1000000 : isThousands ? 1000 : 1
|
|
|
|
const suffix = isMillions ? 'm' : isThousands ? 'k' : ''
|
2020-02-08 01:12:01 -05:00
|
|
|
return (
|
2020-08-17 15:07:16 -05:00
|
|
|
<React.Fragment>
|
2021-01-09 20:39:59 -05:00
|
|
|
<FormattedNumber value={number / divisor} maximumFractionDigits={1} />{suffix}
|
2020-08-17 15:07:16 -05:00
|
|
|
</React.Fragment>
|
2020-02-08 01:12:01 -05:00
|
|
|
)
|
|
|
|
}
|
2020-07-28 15:07:55 -05:00
|
|
|
|
|
|
|
export const getRandomInt = (min, max) => {
|
|
|
|
min = Math.ceil(min)
|
|
|
|
max = Math.floor(max)
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min
|
|
|
|
}
|