From f097e21e03cbffde9e396af0b2cfcac285a9612f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Jul 2013 12:21:44 -0400 Subject: Display byte sizes with more precision. --- Utility/DataUnits.hs | 15 +++++++++++---- debian/changelog | 1 + 2 files changed, 12 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 diff --git a/debian/changelog b/debian/changelog index b74fb33c9..cecf996d2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,7 @@ git-annex (4.20130710) UNRELEASED; urgency=low proceed on to the next file, rather than dying. * Fix checking when content is present in a non-bare repository accessed via http. + * Display byte sizes with more precision. -- Joey Hess Tue, 09 Jul 2013 19:17:13 -0400 -- cgit v1.2.3