js 金额加上单位
作者:互联网
/**取截金额单位
* arg 金额:单位元
* return 金额+单位 11.24万元
*/
function numberFormat(arg) {
function strNumSize(tempNum) {
var stringNum = tempNum.toString()
var index = stringNum.indexOf(".")
var newNum = stringNum
if (index != -1) {
newNum = stringNum.substring(0, index)
}
return newNum.length
}
var moneyUnits = ["元", "万元", "亿元", "万亿"]
var dividend = 10000
var curentNum = arg
//转换数字
var curentUnit = moneyUnits[0]
//转换单位
for (var i = 0; i < 4; i++) {
curentUnit = moneyUnits[i]
if (strNumSize(curentNum) < 5) {
break
}
curentNum = curentNum / dividend
}
var m = { num: 0, unit: "" }
m.num = curentNum.toFixed(2)
m.unit = curentUnit
return m.num + m.unit
}
标签:stringNum,加上,金额,js,num,curentNum,arg,var,unit 来源: https://blog.csdn.net/qq_38985444/article/details/120221380