我是靠谱客的博主 稳重小刺猬,这篇文章主要介绍金额格式化,现在分享给大家,希望可以做个参考。

// 金额格式化,20000->20.000
moneyFormat(num) {
    const RegExp = /B(?=(?:d{3})+(?!d))/g
    if (num === undefined || num === null) return
    num = num.toString()
    if (num.indexOf('.') >= 0) {
      var lastIndex = num.lastIndexOf('.')
      var betweenDot = num.substring(lastIndex + 1, num.length)
      if (betweenDot && parseInt(betweenDot)) {
        const beforeDot = num.substring(0, lastIndex)
        const bereeDotFormat = beforeDot && beforeDot.toString().replace(RegExp, '.')
        num =
        bereeDotFormat +
        ',' +
        num.substring(lastIndex + 1, num.length)
        return num
      } else {
        const tempNum = num.substring(0, lastIndex)
        num = tempNum && tempNum.toString().replace(RegExp, '.')
        return num
      }
    }
    let numformat = num && num.toString().replace(RegExp, '.')
    return numformat
  },

最后

以上就是稳重小刺猬最近收集整理的关于金额格式化的全部内容,更多相关金额格式化内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部