Created
June 25, 2018 12:22
-
-
Save DawnImpulse/ddac80db5734c2295008abacc4885d06 to your computer and use it in GitHub Desktop.
Use to add suffix like 2k & 8M to numbers
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
fun withSuffix(count: Int): String { | |
if (count < 1000) return "" + count | |
val exp = (Math.log(count.toDouble()) / Math.log(1000.0)).toInt() | |
return String.format("%.1f %c", | |
count / Math.pow(1000.0, exp.toDouble()), | |
"kMGTPE"[exp - 1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment