-
-
Save dipeshhkc/43e763ebae7e7ba3f533a5e60126b546 to your computer and use it in GitHub Desktop.
Minimize Number into K, M, G, T, P, E
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 minimizeNumber = (num) => { | |
if(!Number.isFinite(num)) return ""; | |
const minimizeMap = ["K", "M", "G", "T", "P", "E"]; | |
if(num < 1000) return num.toString(); | |
const exp = Math.floor(Math.log(num)/ Math.log(1000)); | |
const minimized = Number((num / Math.pow(1000, exp)).toFixed(2)); | |
return minimized+minimizeMap[exp-1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment