diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-06-26 12:15:27 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-06-26 12:15:55 -0400 |
commit | 63f9aba33b45e5bab688ffaa5e4182801c152828 (patch) | |
tree | 1f4e16640503b27bbd0f33241cbe1cb2c4a4eb89 /Utility/HumanNumber.hs | |
parent | c799b05deae723690bfac5e867f7985e8f800d0d (diff) | |
download | git-repair-63f9aba33b45e5bab688ffaa5e4182801c152828.tar.gz |
merge from git-annex
Removes dependency on MissingH, adding a dependency on split instead.
This commit was sponsored by Brock Spratlen on Patreon.
Diffstat (limited to 'Utility/HumanNumber.hs')
-rw-r--r-- | Utility/HumanNumber.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Utility/HumanNumber.hs b/Utility/HumanNumber.hs new file mode 100644 index 0000000..c3fede9 --- /dev/null +++ b/Utility/HumanNumber.hs @@ -0,0 +1,21 @@ +{- numbers for humans + - + - Copyright 2012-2013 Joey Hess <id@joeyh.name> + - + - License: BSD-2-clause + -} + +module Utility.HumanNumber where + +{- Displays a fractional value as a string with a limited number + - of decimal digits. -} +showImprecise :: RealFrac a => Int -> a -> String +showImprecise precision n + | precision == 0 || remainder == 0 = show (round n :: Integer) + | otherwise = show int ++ "." ++ striptrailing0s (pad0s $ show remainder) + where + int :: Integer + (int, frac) = properFraction n + remainder = round (frac * 10 ^ precision) :: Integer + pad0s s = replicate (precision - length s) '0' ++ s + striptrailing0s = reverse . dropWhile (== '0') . reverse |