-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: use colorful chips for post tags
- Loading branch information
1 parent
56bdfa2
commit dd53829
Showing
6 changed files
with
393 additions
and
138 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
app-alpha/src/main/java/com/github/uragiristereo/mejiboard/common/helper/NumberHelper.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.uragiristereo.mejiboard.common.helper | ||
|
||
import kotlin.math.floor | ||
import kotlin.math.ln | ||
import kotlin.math.pow | ||
import kotlin.math.roundToInt | ||
|
||
object NumberHelper { | ||
fun convertToReadable(number: Int): String { | ||
if (number < 1000) | ||
return "$number" | ||
|
||
val units = listOf(' ', 'K', 'M', 'G') | ||
|
||
val i = floor(ln(number.toDouble()) / ln(1000.0)) | ||
val p = 1000.0.pow(i) | ||
val s = (number / p * 100).roundToInt() / 100.0 | ||
|
||
return if (s > 10) { | ||
"%d%s".format(s.roundToInt(), units[i.toInt()]) | ||
} else { | ||
"%.1f%s".format(s, units[i.toInt()]) | ||
.replace(oldValue = ".0", newValue = "") | ||
} | ||
} | ||
} |
Oops, something went wrong.