Vue.filter('money', (value, symbol = '', currency = '¥', decimals = 0) => {
const digitsRE = /(\d{3})(?=\d)/g
value = parseFloat(value)
if (!isFinite(value) || (!value && value !== 0)) return ''
currency = currency != null ? currency : '$'
decimals = decimals != null ? decimals : 2
let stringified = Math.abs(value).toFixed(decimals)
let _int = decimals ?
stringified.slice(0, -1 - decimals) :
stringified
let i = _int.length % 3
let head = i > 0 ?
(_int.slice(0, i) + (_int.length > 3 ? symbol : '')) :
''
let _float = decimals ?
stringified.slice(-1 - decimals) :
''
let sign = value < 0 ? '-' : ''
return sign + currency + head +
_int.slice(i).replace(digitsRE, '$1,') +
_float
})
Vue.filter('percent', value => { // 百分比
return `${value}%`
})
Vue.filter('FormatMoney', (value, hasDecimal) => { // 千位数字以上*代替
value = parseFloat(value).toFixed(hasDecimal)
let result = '';
let b = value.split(".")
for (let i = 0; b[0].length > 3; i++) {
if (i == 0) {
result = ',' + b[0].slice(-3) + result
} else {
result = ',***' + result
}
b[0] = b[0].slice(0, b[0].length - 3)
}
if (b[0]) {
if (result.length > 0) {
for (var y = 0; b[0].length > y; y++) {
result = "*" + result
}
} else {
result = b[0] + result
}
}
if (b[1]) {
return result + '.' + b[1]
}
return result
})
Vue.filter('currency', (value, hasDecimal) => { // 数量格式化
if (hasDecimal) {
value = parseFloat(value).toFixed(hasDecimal)
}
return value && value.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') || 0
})
Vue.filter('time', (value, mark = '-') => {
if (!value)
return
let time = new Date(value)
return moment(time).format(`YYYY${mark}MM${mark}DD`)
})

最新文章

  1. 图解Javascript原型链
  2. 不可或缺 Windows Native (11) - C++: hello c++, C++ 与 C语言的区别小介
  3. Scalaz(36)- Free :实践-Free In Action - 实用体验
  4. 【bzoj1001】 BeiJing2006—狼抓兔子
  5. ssh安装与配置
  6. 你会在C#的类库中添加web service引用吗?
  7. selenium+python find_element_by_css_selector方法使用
  8. mysql innodb 引擎
  9. https_request请求接口返回数据
  10. Jsp 中文乱码,解决
  11. Entity Framework with MySQL 学习笔记一(复杂类型 Complex Types)
  12. java Socket使用注意
  13. 面试题25:最小的K个数
  14. iscroll实现移动端下拉刷新,上拉加载更多
  15. [Swift]LeetCode1 .两数之和 | Two Sum
  16. 29.Hibernate-二级缓存和session管理.md
  17. http协议返回码
  18. Centos 7 设置ssh只允许特定用户从指定的IP登录
  19. mysql 全文搜索(转载http://blog.csdn.net/manbujingxin/article/details/6656992)
  20. WCF 基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。

热门文章

  1. Android(java)学习笔记94: SurfaceView使用
  2. iOS中的崩溃类型
  3. 将bat批处理文件注册成windows服务
  4. 用fast rcnn绘制loss曲线遇到的问题
  5. mongo 4.0以下版本 类型转换
  6. [C++]#if !defined 的作用
  7. ASP.NET 与 Ajax 的实现方式
  8. 用Java实现excel转txt
  9. git 命令汇总
  10. Linux的链接文件