<span>{{ val| currency(symbol, decimals) }}</span>
const currency = (value, _currency = '$', decimals = 2) => {
const digitsRE = /(\d{3})(?=\d)/g
value = parseFloat(value)
if (!isFinite(value) || !value && value !== 0) return ''
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 ? ',' : '') : ''
let _float = decimals ? stringified.slice(-1 - decimals) : ''
let sign = value < 0 ? '-' : ''
return sign + _currency + head + _int.slice(i).replace(digitsRE, '$1,') + _float
}
export default {
data () {
return {
val: 12345,
symbol:'¥',
decimals:2
}
},
filters: {
currency
},
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29