about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/numbers.js
blob: af18dcfddb2a80cb552206d553938a03d9a53d4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import React, { Fragment } from 'react';
import { FormattedNumber } from 'react-intl';

export const shortNumberFormat = number => {
  if (number < 1000) {
    return <FormattedNumber value={number} />;
  } else if (number < 10000) {
    return <Fragment><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</Fragment>;
  } else if (number < 1000000) {
    return <Fragment><FormattedNumber value={number / 1000} maximumFractionDigits={0} />K</Fragment>;
  } else if (number < 10000000) {
    return <Fragment><FormattedNumber value={number / 1000000} maximumFractionDigits={1} />M</Fragment>;
  } else {
    return <Fragment><FormattedNumber value={number / 1000000} maximumFractionDigits={0} />M</Fragment>;
  }
};