Skip to content

Instantly share code, notes, and snippets.

@kerimovscreations
Last active June 8, 2020 13:05
Show Gist options
  • Save kerimovscreations/25528a4fc31acb4df268fe5dedfc5978 to your computer and use it in GitHub Desktop.
Save kerimovscreations/25528a4fc31acb4df268fe5dedfc5978 to your computer and use it in GitHub Desktop.
fun getShortenedCount(count: Int): String {
return if (count < 1000) {
count.toString()
} else if (count < 1000000) {
val firstPart = count / 1000
val secondPart = count % 1000 / 100
if (secondPart > 0) {
"$firstPart,${secondPart}k}"
} else {
"${firstPart}k"
}
} else if (count < 1000000000) {
val firstPart = count / 1000000
val secondPart = count % 1000000 / 100000
if (secondPart > 0) {
"$firstPart,${secondPart}m"
} else {
"${firstPart}m"
}
} else {
count.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment