Skip to content

Instantly share code, notes, and snippets.

@vunb
Created July 18, 2016 05:59
Show Gist options
  • Save vunb/84d337fdf9c8b071d20bdcafbe479ce2 to your computer and use it in GitHub Desktop.
Save vunb/84d337fdf9c8b071d20bdcafbe479ce2 to your computer and use it in GitHub Desktop.
Đổi những số quá dài thành K (trăm ngàn), M (triệu), B(tỷ)
var convert = function(num){
var arrV = [1E9,1E6,1E3],
arrS = ['B','M','K'],
result = num;
arrV.forEach(function(item,index){
if (num < item) return;
var value = Math.ceil(num/item);
if (value<1000 && value >=1) {
result = arrS[index];
};
});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment