zoukankan      html  css  js  c++  java
  • Vue自定义过滤器格式化数字三位加一逗号

    <template>
    <div class="index-compont">
       <div class="totalCount">{{num | NumFormat}}<span>元</span></div>
    </div>
    </template>
    <script>
    data(){
        return {
        num: 876543.00 } }, filters: { NumFormat: function (value) { if(!value) return '0.00' value = value.toFixed(2) var intPart = Math.trunc(value)// 获取整数部分
          var intPartFormat = intPart.toString().replace(/(d)(?=(?:d{3})+$)/g, '$1,') // 将整数部分逢三一断
          var floatPart = '.00' // 预定义小数部分
          var value2Array = value.split('.')
          // =2表示数据有小数位
          if(value2Array.length === 2) {
            floatPart = value2Array[1].toString() // 拿到小数部分
            if(floatPart.length === 1) { // 补0,实际上用不着
              return intPartFormat + '.' + floatPart + '0'
            } else {
              return intPartFormat + '.' + floatPart
            }
          } else {
            return intPartFormat + floatPart
          }
        }
      }
    </script>
    

      

  • 相关阅读:
    Unity模型导入导出
    3D知识补充
    Unity. Navigation和寻路
    Unity坐标系
    Unity材质
    Unity摄像机
    Unity光照
    Unity资源管理与更新
    Unity垃圾回收
    intellij idea 的全局搜索快捷键方法
  • 原文地址:https://www.cnblogs.com/wanf/p/9154511.html
Copyright © 2011-2022 走看看