Vue 過濾方法 數字補零

Vue.filter('allFilter', (value = '') => {
  if (!['[object Number]', '[object String]'].includes(Object.prototype.toString.call(value))) {
    return value
  }
  let num = value.toString().replace(/^(\d+)(\.\d+)?$/g, (big, ...args) => {
    let [a, b] = args
    if (!b) b = '.'
    while (b.length <= 2) {
      b += '0'
    }
    return a + b
  })
  return num
})

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章