Created
July 18, 2016 05:59
-
-
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ỷ)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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