bigbuffet-rw/app/soapbox/utils/numbers.js

15 lines
415 B
JavaScript
Raw Normal View History

2020-04-14 13:45:38 -07:00
import React from 'react';
2020-03-27 13:59:38 -07:00
import { FormattedNumber } from 'react-intl';
2021-07-13 12:26:34 -07:00
const isNumber = number => typeof number === 'number' && number !== NaN;
2020-03-27 13:59:38 -07:00
export const shortNumberFormat = number => {
2021-07-13 12:26:34 -07:00
if (!isNumber(number)) return '•';
2020-03-27 13:59:38 -07:00
if (number < 1000) {
return <FormattedNumber value={number} />;
} else {
return <span><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</span>;
}
};