8ea5f3ff99
Eliminated some dead code. In other cases, exported a currently unused function, since it was a logical part of the API. Of course this improves the API documentation. It may also sometimes let ghc optimize code better, since it can know a function is internal to a module. 364 modules still to go, according to git grep -E 'module [A-Za-z.]+ where'
21 lines
683 B
Haskell
21 lines
683 B
Haskell
{- numbers for humans
|
|
-
|
|
- Copyright 2012-2013 Joey Hess <id@joeyh.name>
|
|
-
|
|
- License: BSD-2-clause
|
|
-}
|
|
|
|
module Utility.HumanNumber (showImprecise) 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
|