Skip to content

Instantly share code, notes, and snippets.

@DawnImpulse
Created June 25, 2018 12:22
Show Gist options
  • Save DawnImpulse/ddac80db5734c2295008abacc4885d06 to your computer and use it in GitHub Desktop.
Save DawnImpulse/ddac80db5734c2295008abacc4885d06 to your computer and use it in GitHub Desktop.
Use to add suffix like 2k & 8M to numbers
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