Created
March 9, 2020 23:04
-
-
Save motia/282878d4b75b3845f481477a3bc21aa3 to your computer and use it in GitHub Desktop.
This file contains 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
function round(value, precision) { | |
var multiplier = Math.pow(10, precision || 0); | |
var num = (Math.round(value * multiplier) / multiplier).toString(); | |
return num.indexOf('.') ? num : num + '.0'; | |
} | |
function shortNumberFormatter(number) { | |
if (number < 900) { | |
return number; | |
} | |
var chars = ['', 'k', 'm', 'b', 't']; | |
for (var i = 0; i < chars.length; i++) { | |
var temp = number / Math.pow(10, (i) * 3); | |
if (temp > 90) { | |
continue; | |
} | |
return round(temp, 1) + chars[i]; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment