Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Fixes #4616: add MemorySize.toSizeMo function #33

Merged
merged 1 commit into from Mar 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -127,11 +127,25 @@ object MemorySize {
* It returns a string representation of the value and a string representation of the unit
* to let it be i18n-able
*/
def prettyMo(m:MemorySize) = {
def prettyMo(m:MemorySize) : (String,String) = {
val x = prettyPrint(m, "B" :: "kB" :: "MB" :: "GB" :: "TB" :: "PB" :: "EB" :: "ZB" :: "YB" :: Nil)
(x._1.bigDecimal.stripTrailingZeros.toPlainString,x._2)
}

/**
* Get the size in megabyte as a Long of the MemorySize passed as parameter
* compared to prettyMo it always return a size in megabyte and does not display the trailing unit
*/
def sizeMb(m:MemorySize) : Long = {
val size: BigDecimal = m.size
val mb = size / Ko / Ko
if (mb < 1) {
0
} else {
mb.toLong
}
}

/**
* @param m : The memory quantity to pretty print
* @param units : The list of available units. Can not be null.
Expand Down