From b89ed118caaf168222414a365e5227531473e6c0 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 12 Apr 2015 17:20:43 +0200 Subject: [PATCH] proper negative float formatting --- Foundation.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Foundation.hs b/Foundation.hs index c751473..a579377 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -28,11 +28,14 @@ prependZero t0 = if T.null t1 where t1 = T.dropWhile ((==) ' ') t0 formatFloat :: Double -> Text -formatFloat d = T.pack (t ++ c) +formatFloat d = T.pack (pre ++ t ++ c) where t = reverse (intercalate "." $ chunksOf 3 $ reverse $ fst sp) c = "," ++ tail (snd sp) - sp = (break (== '.') (printf "%.2f" d)) + sp = (break (== '.') (printf "%.2f" (abs d))) + pre = case d < 0 of + True -> "-" + False -> "" -- T.pack . (splitEvery 3) . (printf "%,2f") formatIntCurrency :: Int -> Text