优化代码

pull/768/head
gedoor 4 years ago
parent fa72c4e698
commit 1adce9267b
  1. 4
      app/src/main/java/io/legado/app/utils/StringUtils.kt

@ -106,11 +106,9 @@ object StringUtils {
if (length <= 0) return "0"
val units = arrayOf("b", "kb", "M", "G", "T")
//计算单位的,原理是利用lg,公式是 lg(1024^n) = nlg(1024),最后 nlg(1024)/lg(1024) = n。
//计算单位的,原理是利用lg,公式是 lg(1024^n) = nlg(1024),最后 nlg(1024)/lg(1024) = n。
val digitGroups =
(log10(length.toDouble()) / log10(1024.0)).toInt()
//计算原理是,size/单位值。单位值指的是:比如说b = 1024,KB = 1024^2
//计算原理是,size/单位值。单位值指的是:比如说b = 1024,KB = 1024^2
return DecimalFormat("#,##0.##")
.format(length / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups]
}
@ -306,7 +304,7 @@ object StringUtils {
return sb.toString()
}
fun hexStringToByte(hexString: String): ByteArray? {
fun hexStringToByte(hexString: String): ByteArray {
val hexStr = hexString.replace(" ", "")
val len = hexStr.length
val bytes = ByteArray(len / 2)

Loading…
Cancel
Save