public static currencyUnit(currency:string){
let length = currency.length;
if(length <= 3){
return currency;
}
// currency = '10000';
let units = ['','K','M','B','T','aa','bb','cc','dd','ee','ff',
'gg','hh','ii','jj','kk','ll','mm','nn','oo'];
let times = Math.floor((length-1)/3);
let remainder = length%3;
remainder = remainder == 0 ? 3 : remainder;
let unit = '';
for(let i=0;i<remainder;i++){
unit+=currency[i];
}
unit+='.';
unit+=currency[remainder];
unit+=units[times];
console.log('unit == '+unit);
return unit;
}
比如传入:
XXX.currencyUnit('2405610200000');
unit == 2.4T