gab-social/app/javascript/gabsocial/utils/numbers.js
mgabdev a38d9f6133 Added number util function for getRandomInt
• Added:
- number util function for getRandomInt
2020-07-28 15:07:55 -05:00

24 lines
577 B
JavaScript

import { Fragment } from 'react'
import { FormattedNumber } from 'react-intl'
export const shortNumberFormat = (number) => {
if (number < 1000) {
try {
return (<FormattedNumber value={number} />).props.value
} catch (error) {
return <FormattedNumber value={number} />
}
}
return (
<Fragment>
<FormattedNumber value={number / 1000} maximumFractionDigits={1} />k
</Fragment>
)
}
export const getRandomInt = (min, max) => {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min + 1)) + min
}