Last active
June 8, 2020 13:05
-
-
Save kerimovscreations/25528a4fc31acb4df268fe5dedfc5978 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
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