Skip to content

Commit

Permalink
Use kotlin functions
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoriiioffe committed Mar 8, 2023
1 parent feacd12 commit 87cadf5
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.keylesspalace.tusky.util

import java.text.DecimalFormat
import kotlin.math.floor
import kotlin.math.log10

fun shortNumber(number: Number): String {
val array = arrayOf(' ', 'k', 'M', 'B', 'T', 'P', 'E')
val value = Math.floor(Math.log10(number.toDouble())).toInt()
val value = floor(log10(number.toDouble())).toInt()
val base = value / 3
if (value >= 3 && base < array.size) {
return DecimalFormat("#0.0").format(number.toDouble() / Math.pow(10.0, (base * 3).toDouble())) + array[base]
Expand Down

0 comments on commit 87cadf5

Please sign in to comment.