const replaceOnlyNumber = (value: string) => {
  return value.replace(/[^0-9.]/g, '');
};

const numFormatter = (num?: number): string => {
  if (!num) {
    return '0';
  }

  if (num > 999 || num < 1000000) {
    return (Math.floor((num / 1000) * 10) / 10) + 'K';
  } else if (num > 1000000) {
    return (Math.floor((num / 1000000) * 10) / 10) + 'M';
  }

  return num.toString();
};

const formatBalance = (num: number | undefined) => {
  if (!num) {
    return 0;
  }
  return Math.floor(num * 100000) / 100000;
}

export default {
  replaceOnlyNumber,
  numFormatter,
  formatBalance,
};
