/*
 * @Author: WangQiBiao
 * @LastEditors: WangQiBiao
 * @Description: 数字格式化
 * @Date: 2019-04-19 10:42:31
 * @LastEditTime: 2019-09-26 15:34:36
 */
/**
 * @param {number} num
 * @returns {number}
 */
export function toFixed (num, floatLen = 2) {
  if (isNaN(Number(num))) {
    return num
  } else {
    return Number(num).toFixed(floatLen)
  }
}
/**
 * 数字格式化 12,123,123
 */
export function numberFormat (num) {
  if (isNaN(Number(num))) {
    return num
  } else {
    return String(num).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
  }
}
/**
 * 金额格式化 12,123,123.00
 */
export function moneyFormat (num = 2) {
  if (num === null || num === undefined) {
    return ''
  }
  return numberFormat(toFixed(num))
}
