proper negative float formatting

This commit is contained in:
nek0 2015-04-12 17:20:43 +02:00
parent 72692fa9ce
commit b89ed118ca
1 changed files with 5 additions and 2 deletions

View File

@ -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