summaryrefslogtreecommitdiff
path: root/Utility/DataUnits.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-07-19 12:21:44 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-07-19 12:21:44 -0400
commitf097e21e03cbffde9e396af0b2cfcac285a9612f (patch)
tree90e5fd8547f3cbb8e68342608903a2fc5c1b13a8 /Utility/DataUnits.hs
parent164e979ead3e094572542857f76e520fadbd59df (diff)
Display byte sizes with more precision.
Diffstat (limited to 'Utility/DataUnits.hs')
-rw-r--r--Utility/DataUnits.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/Utility/DataUnits.hs b/Utility/DataUnits.hs
index c6990fdfb..e5c2fc83e 100644
--- a/Utility/DataUnits.hs
+++ b/Utility/DataUnits.hs
@@ -116,12 +116,19 @@ roughSize units abbrev i
| otherwise = findUnit us i'
findUnit [] i' = showUnit i' (last units') -- bytes
- showUnit i' (Unit s a n) = let num = chop i' s in
- show num ++ " " ++
+ showUnit i' (Unit s a n) = let (num, decimal) = chop i' s in
+ show num ++ decimal ++ " " ++
(if abbrev then a else plural num n)
- chop :: Integer -> Integer -> Integer
- chop i' d = round $ (fromInteger i' :: Double) / fromInteger d
+ chop :: Integer -> Integer -> (Integer, String)
+ chop i' d =
+ let (num, decimal) = properFraction $ (fromInteger i' :: Double) / fromInteger d
+ dnum = round (decimal * 100) :: Integer
+ ds = show dnum
+ ds' = (take (2 - length ds) (repeat '0')) ++ ds
+ in if (dnum == 0)
+ then (num, "")
+ else (num, "." ++ ds')
plural n u
| n == 1 = u