小程序增加货币js工具类
This commit is contained in:
19
src/components/utils/coin.js
Normal file
19
src/components/utils/coin.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export default {
|
||||||
|
cny(money) {
|
||||||
|
if (money) {
|
||||||
|
money.toLocaleString('zh-Hans-CN', {style: 'currency', currency: "CNY"})
|
||||||
|
}
|
||||||
|
return money
|
||||||
|
},
|
||||||
|
cn(money) {
|
||||||
|
let num = parseFloat(money), cnMoney = '',
|
||||||
|
units = '仟佰拾亿仟佰拾万仟佰拾元角分',
|
||||||
|
cnNum = '零壹贰叁肆伍陆柒捌玖'
|
||||||
|
num = num.toFixed(2).replace(/\./g, '')
|
||||||
|
units = units.substring(units.length - num.length)
|
||||||
|
Array.from(num).map((e, i) => {
|
||||||
|
cnMoney += cnNum.charAt(e) + units.charAt(i)
|
||||||
|
})
|
||||||
|
return cnMoney.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import $dayjs from './moment'
|
import $dayjs from './moment'
|
||||||
import $dict from './dict'
|
import $dict from './dict'
|
||||||
import $qs from 'query-string'
|
import $qs from 'query-string'
|
||||||
|
import $coin from './coin'
|
||||||
|
|
||||||
const $toast = (obj) => {
|
const $toast = (obj) => {
|
||||||
let params = {title: '', duration: 2000, icon: 'none'};
|
let params = {title: '', duration: 2000, icon: 'none'};
|
||||||
@@ -342,5 +343,6 @@ export default {
|
|||||||
$dayjs,
|
$dayjs,
|
||||||
$dict,
|
$dict,
|
||||||
$getLoginCode,
|
$getLoginCode,
|
||||||
$qs
|
$qs,
|
||||||
|
$coin
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user