All Downloads are FREE. Search and download functionalities are using the official Maven repository.

clouseau.Units.scala Maven / Gradle / Ivy

There is a newer version: 0.2.2
Show newest version
package clouseau

object Units {
  def bytes(bytes: Long): String = s"${bytes}B"

  val si: List[String] = List("B", "K", "M", "G", "T", "P", "E", "Z", "Y")

  def approx(bytes: Long): String = {
    def loop(value: Double, units: List[String]): String =
      if (value < 1024.0) "%.3g%s".format(value, units.head)
      else loop(value / 1024.0, units.tail)
    loop(bytes.toDouble, si)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy