/**
 * 格式化一个数字为万或亿
 * @param {string|number} num
 * @param {boolean} isZhTw
 * @returns
 */
function formatNum(num, isZhTw) {
  var intNum = parseInt(num, 10);

  if (Number.isNaN(intNum) || intNum < 0) {
    return '';
  }

  if (intNum >= 10000 && intNum < 100000000) {
    return (intNum / 10000).toFixed(1) + (isZhTw ? '萬' : '万');
  }

  if (intNum >= 100000000) {
    return (intNum / 100000000).toFixed(1) + (isZhTw ? '億' : '亿');
  }

  if (/\./.test(num)) {
    return num;
  }

  return intNum;
}

export default formatNum;
