summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKrzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com>2007-07-12 03:36:26 +0200
committerKrzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com>2007-07-12 03:36:26 +0200
commit2217463c0f52280835bf508dd5b768bff56f2b65 (patch)
treeaadf5f6247588d93e4a2f10fcedf2237e1014ecd
parent57b8cee954996394d0ba7212819ffe592d2148b4 (diff)
downloadxmobar-2217463c0f52280835bf508dd5b768bff56f2b65.tar.gz
xmobar-2217463c0f52280835bf508dd5b768bff56f2b65.tar.bz2
Get rid of floats in scientific notation.
Use 'showDigits n' instead of 'show . takeDigits n'. As this example shows explicit precision specifications would be appreciated ;) darcs-hash:20070712013626-ba08c-868a9d53ab1b8bc120d7c1a9634d3d8c7cb599d7.gz
-rw-r--r--Plugins/Monitors/Common.hs7
-rw-r--r--Plugins/Monitors/Mem.hs2
-rw-r--r--Plugins/Monitors/Net.hs2
-rw-r--r--Plugins/Monitors/Swap.hs2
-rw-r--r--Plugins/Monitors/Weather.hs2
5 files changed, 10 insertions, 5 deletions
diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs
index 8e2703f..1c92fb8 100644
--- a/Plugins/Monitors/Common.hs
+++ b/Plugins/Monitors/Common.hs
@@ -37,6 +37,7 @@ module Plugins.Monitors.Common (
-- $strings
, showWithColors
, takeDigits
+ , showDigits
, floatToPercent
, stringParser
-- * Threaded Actions
@@ -242,9 +243,13 @@ takeDigits d n =
fromIntegral ((round (n * fact)) :: Int) / fact
where fact = 10 ^ d
+showDigits :: Int -> Float -> String
+showDigits d n =
+ showFFloat (Just d) n ""
+
floatToPercent :: Float -> String
floatToPercent n =
- showFFloat (Just 2) (n*100) "%"
+ showDigits 2 (n*100) ++ "%"
stringParser :: Pos -> B.ByteString -> String
stringParser (x,y) =
diff --git a/Plugins/Monitors/Mem.hs b/Plugins/Monitors/Mem.hs
index 56639f2..2236256 100644
--- a/Plugins/Monitors/Mem.hs
+++ b/Plugins/Monitors/Mem.hs
@@ -37,7 +37,7 @@ parseMEM =
formatMem :: [Float] -> Monitor [String]
formatMem x =
- do let f n = show (takeDigits 2 n)
+ do let f n = showDigits 2 n
mapM (showWithColors f) x
runMem :: [String] -> Monitor String
diff --git a/Plugins/Monitors/Net.hs b/Plugins/Monitors/Net.hs
index 8534a2a..6a7f01f 100644
--- a/Plugins/Monitors/Net.hs
+++ b/Plugins/Monitors/Net.hs
@@ -71,7 +71,7 @@ netParser =
formatNet :: Float -> Monitor String
formatNet d =
showWithColors f d
- where f s = show s ++ "Kb"
+ where f s = showDigits 1 s ++ "Kb"
printNet :: NetDev -> Monitor String
printNet nd =
diff --git a/Plugins/Monitors/Swap.hs b/Plugins/Monitors/Swap.hs
index fbddaae..d18ab8a 100644
--- a/Plugins/Monitors/Swap.hs
+++ b/Plugins/Monitors/Swap.hs
@@ -36,7 +36,7 @@ parseMEM =
formatSwap :: [Float] -> Monitor [String]
formatSwap x =
- do let f1 n = show (takeDigits 2 n)
+ do let f1 n = showDigits 2 n
f2 n = floatToPercent n
(hd, tl) = splitAt 3 x
firsts <- mapM (showWithColors f1) hd
diff --git a/Plugins/Monitors/Weather.hs b/Plugins/Monitors/Weather.hs
index ec5606e..447ac2c 100644
--- a/Plugins/Monitors/Weather.hs
+++ b/Plugins/Monitors/Weather.hs
@@ -117,7 +117,7 @@ getData url=
formatWeather :: [WeatherInfo] -> Monitor String
formatWeather [(WI st ss y m d h w v sk temp dp r p)] =
do cel <- showWithColors show temp
- far <- showWithColors (show . takeDigits 1) (((9 / 5) * temp) + 32)
+ far <- showWithColors (showDigits 1) (((9 / 5) * temp) + 32)
rh <- showWithColors show r
parseTemplate [st, ss, y, m, d, h, w, v, sk, cel, far, dp, rh , p ]
formatWeather _ = return "N/A"