better float formatting
This commit is contained in:
parent
acdf3e85e1
commit
e552c398df
2 changed files with 9 additions and 1 deletions
|
@ -5,6 +5,8 @@ import Data.FileEmbed (embedFile)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Lazy.Encoding as E
|
import qualified Data.Text.Lazy.Encoding as E
|
||||||
import qualified Data.Text.Read as R
|
import qualified Data.Text.Read as R
|
||||||
|
import Data.List (tail)
|
||||||
|
import Data.List.Split
|
||||||
import Yesod.Form.Functions
|
import Yesod.Form.Functions
|
||||||
import Text.Shakespeare.Text
|
import Text.Shakespeare.Text
|
||||||
import Network.Mail.Mime
|
import Network.Mail.Mime
|
||||||
|
@ -123,7 +125,12 @@ prependZero t0 = if T.null t1
|
||||||
where t1 = T.dropWhile ((==) ' ') t0
|
where t1 = T.dropWhile ((==) ' ') t0
|
||||||
|
|
||||||
formatFloat :: Double -> Text
|
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 :: Int -> Text
|
||||||
formatIntCurrency x = formatFloat $ ((fromIntegral x) / 100)
|
formatIntCurrency x = formatFloat $ ((fromIntegral x) / 100)
|
||||||
|
|
|
@ -93,6 +93,7 @@ library
|
||||||
, blaze-markup
|
, blaze-markup
|
||||||
, wai
|
, wai
|
||||||
, blaze-builder < 0.4.0.0
|
, blaze-builder < 0.4.0.0
|
||||||
|
, split
|
||||||
|
|
||||||
executable yammat
|
executable yammat
|
||||||
if flag(library-only)
|
if flag(library-only)
|
||||||
|
|
Loading…
Reference in a new issue