-- | Shows a Float with the least number of decimals possible, with a maximum 
--   of d decimals.
--
-- >>> showFFloat' 3 2.0000001 
-- "2"
-- >>> showFFloat' 3 2.1234567 
-- "2.123"
-- >>> showFFloat' 3 10.000001
-- "10"
showFFloat' :: Int -> Float -> String
showFFloat' d f = wholeNumbers ++ removeTrailingZeros (take (d + 1) decimals)
    where 
        (wholeNumbers, decimals) = break ('.' ==) $ showFFloat Nothing f ""
        removeTrailingZeros []                  = []
        removeTrailingZeros xs | last xs == '0' = removeTrailingZeros (init xs)
                               | last xs == '.' = removeTrailingZeros (init xs)
                               | otherwise      = xs


-----------------------------------------------------------------------------


-- | Gets a given quantile from a list of values.
--
-- >>> quantile 0.25 [1,2,3,4,5]
-- 2.0
-- >>> quantile 0.75 [1,2,3,4,5]
-- 4.0
showFFloat' :: Int -> Float -> String
showFFloat' d f = wholeNumbers ++ removeTrailingZeros (take (d + 1) decimals)
    where 
        (wholeNumbers, decimals) = break ('.' ==) $ showFFloat Nothing f ""
        removeTrailingZeros []                  = []
        removeTrailingZeros xs | last xs == '0' = removeTrailingZeros (init xs)
                               | last xs == '.' = removeTrailingZeros (init xs)
                               | otherwise      = xs


-----------------------------------------------------------------------------


-- | Gets a given quantile from a list of values.
--
-- >>> quantile 0.25 [1,2,3,4,5]
-- 2.0
-- >>> quantile 0.75 [1,2,3,4,5]
-- 4.0
showFFloat' d f = wholeNumbers ++ removeTrailingZeros (take (d + 1) decimals)
    where 
        (wholeNumbers, decimals) = break ('.' ==) $ showFFloat Nothing f ""
        removeTrailingZeros []                  = []
        removeTrailingZeros xs | last xs == '0' = removeTrailingZeros (init xs)
                               | last xs == '.' = removeTrailingZeros (init xs)
                               | otherwise      = xs


-----------------------------------------------------------------------------


-- | Gets a given quantile from a list of values.
--
-- >>> quantile 0.25 [1,2,3,4,5]
-- 2.0
-- >>> quantile 0.75 [1,2,3,4,5]
-- 4.0