nice float formatting

This commit is contained in:
nek0 2015-04-07 16:30:06 +02:00
parent d41aea3bfb
commit 4506d48b50
8 changed files with 16 additions and 8 deletions

View file

@ -8,6 +8,7 @@ import qualified Data.Text.Read as R
import Yesod.Form.Functions import Yesod.Form.Functions
import Text.Shakespeare.Text import Text.Shakespeare.Text
import Network.Mail.Mime import Network.Mail.Mime
import Text.Printf
import Import import Import
-- These handlers embed files in the executable at compile time to avoid a -- These handlers embed files in the executable at compile time to avoid a
@ -120,3 +121,9 @@ prependZero t0 = if T.null t1
else t1 else t1
where t1 = T.dropWhile ((==) ' ') t0 where t1 = T.dropWhile ((==) ' ') t0
formatFloat :: Double -> Text
formatFloat = T.pack . (printf "%.2f")
formatIntCurrency :: Int -> Text
formatIntCurrency x = formatFloat $ ((fromIntegral x) / 100)

View file

@ -2,6 +2,7 @@ module Handler.Summary where
import Import import Import
import Data.List as L import Data.List as L
import Handler.Common
getSummaryR :: Handler Html getSummaryR :: Handler Html
getSummaryR = do getSummaryR = do

View file

@ -3,7 +3,7 @@ $doctype 5
<h3>Kauf von #{beverageIdent bev} <h3>Kauf von #{beverageIdent bev}
<p> <p>
Preis pro Einheit: #{show ((fromIntegral (beveragePrice bev)) / 100)} #{appCurrency $ appSettings master} Preis pro Einheit: #{formatIntCurrency (beveragePrice bev)} #{appCurrency $ appSettings master}
<form method=post enctype=#{enctype}> <form method=post enctype=#{enctype}>
^{buyWidget} ^{buyWidget}

View file

@ -3,7 +3,7 @@ $doctype 5
<h3>Kauf von #{beverageIdent bev} <h3>Kauf von #{beverageIdent bev}
<p> <p>
Preis pro Einheit: #{show ((fromIntegral (beveragePrice bev + 50)) / 100)} #{appCurrency $ appSettings master} Preis pro Einheit: #{formatIntCurrency (beveragePrice bev + 50)} #{appCurrency $ appSettings master}
<form method=post enctype=#{enctype}> <form method=post enctype=#{enctype}>
^{buyCashWidget} ^{buyCashWidget}

View file

@ -13,13 +13,13 @@ $if not $ L.null entries
<tr> <tr>
<td>#{formatTime defaultTimeLocale "%A %F %H:%M" $ transactionTime entry} <td>#{formatTime defaultTimeLocale "%A %F %H:%M" $ transactionTime entry}
<td>#{transactionDescription entry} <td>#{transactionDescription entry}
<td>#{show ((fromIntegral (transactionAmount entry)) / 100)} #{appCurrency $ appSettings master} <td>#{formatIntCurrency (transactionAmount entry)} #{appCurrency $ appSettings master}
<tfoot> <tfoot>
<tr> <tr>
<td colspan="2">Gesamtbetrag: <td colspan="2">Gesamtbetrag:
<td>#{show ((fromIntegral total) / 100)} #{appCurrency $ appSettings master} <td>#{formatIntCurrency (fromIntegral total)} #{appCurrency $ appSettings master}
<p> <p>
Kassenbestand: #{show ((fromIntegral cashBalance) / 100)} #{appCurrency $ appSettings master} Kassenbestand: #{formatIntCurrency (fromIntegral cashBalance)} #{appCurrency $ appSettings master}
<p> <p>
<a href=@{PayoutR}> <a href=@{PayoutR}>

View file

@ -4,7 +4,7 @@ $doctype 5
Guthaben aufladen Guthaben aufladen
<p> <p>
aktuelles Guthaben: #{show ((fromIntegral $ userBalance user) / 100)} aktuelles Guthaben: #{formatIntCurrency (userBalance user)}
<form method=post enctype=#{enctype}> <form method=post enctype=#{enctype}>
^{rechargeWidget} ^{rechargeWidget}

View file

@ -3,7 +3,7 @@ $doctype 5
<div .header> <div .header>
<ul> <ul>
<li> <li>
aktuelles Guthaben: #{show ((fromIntegral (userBalance user)) / 100)} #{appCurrency $ appSettings master} aktuelles Guthaben: #{formatIntCurrency (userBalance user)} #{appCurrency $ appSettings master}
<li> <li>
<a href=@{RechargeR uId}> <a href=@{RechargeR uId}>
Guthaben aufladen Guthaben aufladen

View file

@ -16,7 +16,7 @@ $if not $ L.null bevs
<td>#{beverageIdent bev} <td>#{beverageIdent bev}
<td>#{beverageAmount bev} <td>#{beverageAmount bev}
<td>#{beverageAlertAmount bev} <td>#{beverageAlertAmount bev}
<td>#{show ((fromIntegral (beveragePrice bev)) / 100)} #{appCurrency $ appSettings master} <td>#{formatIntCurrency (beveragePrice bev)} #{appCurrency $ appSettings master}
<td><a href=@{ModifyR bId}>bearbeiten <td><a href=@{ModifyR bId}>bearbeiten
$else $else
<p>keine Getränke vorhanden <p>keine Getränke vorhanden