From 1a04115133ec99ea7b93f848b3d3871c236d5891 Mon Sep 17 00:00:00 2001 From: pingu Date: Mon, 16 Oct 2023 19:10:17 +0200 Subject: [PATCH] Maybe Calle was right? --- app/Main.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 81a0c9f..580ade8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -78,15 +78,18 @@ select = withAttr (attrName "selected") unitSize :: Integer -> String unitSize s - | fromInteger s / (k2^(3 :: Int)) >= 1 / 2 = - show (f $ fromInteger s / (k2^(3 :: Int))) ++ " GB" - | fromInteger s / (k2^(2 :: Int)) >= 1 / 2 = - show (f $ fromInteger s / (k2^(2 :: Int))) ++ " MB" - | fromInteger s / k2 >= 1 / 2 = - show (f $ fromInteger s / k2 ) ++ " KB" - | otherwise = - show s ++ " B" + | s3 >= 1 / 2 = + show (f s3) ++ " GB" + | s2 >= 1 / 2 = + show (f s2) ++ " MB" + | s1 >= 1 / 2 = + show (f s1) ++ " KB" + | otherwise = + show s ++ " B" where k2 = 1024 :: Double + s3 = fromInteger s / (k2^(3 :: Int)) + s2 = fromInteger s / (k2^(2 :: Int)) + s1 = fromInteger s / (k2^(1 :: Int)) f :: Double -> Double f q = fromInteger (truncate $ q * 100) / 100