better float formatting

This commit is contained in:
nek0 2015-04-09 12:35:34 +02:00
parent acdf3e85e1
commit e552c398df
2 changed files with 9 additions and 1 deletions

View file

@ -5,6 +5,8 @@ import Data.FileEmbed (embedFile)
import qualified Data.Text as T
import qualified Data.Text.Lazy.Encoding as E
import qualified Data.Text.Read as R
import Data.List (tail)
import Data.List.Split
import Yesod.Form.Functions
import Text.Shakespeare.Text
import Network.Mail.Mime
@ -123,7 +125,12 @@ prependZero t0 = if T.null t1
where t1 = T.dropWhile ((==) ' ') t0
formatFloat :: Double -> Text
formatFloat = T.pack . (printf "%.2f")
formatFloat d = T.pack (t ++ c)
where
t = reverse (intercalate "." $ chunksOf 3 $ reverse $ fst sp)
c = "," ++ tail (snd sp)
sp = (break (== '.') (printf "%.2f" d))
-- T.pack . (splitEvery 3) . (printf "%,2f")
formatIntCurrency :: Int -> Text
formatIntCurrency x = formatFloat $ ((fromIntegral x) / 100)

View file

@ -93,6 +93,7 @@ library
, blaze-markup
, wai
, blaze-builder < 0.4.0.0
, split
executable yammat
if flag(library-only)