function numFormat(num) {
var NUM,
rules;
if(num === undefined ||num === null)return '0';
NUM = Number(num);
if ( NUM < 10000 )return NUM;
rules = [
{
//大于一万
match: function(param){
return param >= 10000 && param < 10000000;
},
action: function(param){
param = ( Math.round( param / 1000 ) ) / 10 + '万';
return param;
}
},
{
//大于1000万
match: function(param){
return param >= 10000000 && param < 1000000000;
},
action: function(param){
param = ( Math.round( param / 1000000 ) ) / 10 + '千万';
return param;
}
},
{
//大于1亿
match: function(param){
return param >= 1000000000;
},
action: function(param){
param = ( Math.round( param / 10000000 ) ) / 10 + '亿';
return param;
}
}
]
for ( var i = 0; i < rules.length; i++ ){
if( rules[i].match(NUM)){
return rules[i].action(NUM);
}
}
}
var num= numFormat(undefined)
console.log(num)
console