function unitConvertnum) {
var moneyUnits = [“元”, “万元”, “亿元”, “万亿”]
var dividend = 10000;
var curentNum = num;
//转换数字
var curentUnit = moneyUnits[0];
//转换单位
for var i = 0; i <4; i++) {
curentUnit = moneyUnits[i]
ifstrNumSizecurentNum)<5){
break;
}
curentNum = curentNum / dividend
}
var m = {num: 0, unit: “”}
m.num = curentNum.toFixed2)
m.unit = curentUnit;
return m;
}
function strNumSizetempNum){
var stringNum = tempNum.toString)
var index = stringNum.indexOf”.”)
var newNum = stringNum;
ifindex!=-1){
newNum = stringNum.substring0,index)
}
return newNum.length
}
调用并且得到返回值
var data=unitConvert100000);
console.logdata.num+data.unit)