I have a table with a Double field, e.g. foo
. When I capture numbers like 50 million (50000000
) and then I want to view my data, I get: 5.0e7
. When I edit the record again, I also view 5.0e7
on the text field.
I can solve the "show" part using a utility function like:
-- Application/Helper/View.hs
module Application.Helper.View where
import Data.Text (unpack)
-- added format-numbers package as dependency on default.nix
import Data.Text.Format.Numbers
import IHP.ViewPrelude
-- Here you can add functions which are available in all your views
moneyConfiguration :: PrettyCfg
moneyConfiguration = PrettyCfg 2 (Just ',') '.'
showMoneyAmount :: Double -> String
showMoneyAmount d = unpack $ prettyF moneyConfiguration d
Then I use it on Web/View/MyRecord/Show.hs
as:
...
<div class="col">{get #foo myRecord |> showMoneyAmount}</div>
...
But when rendering the form for creating/editing, I can't get rid of the 5.0e7
value:
renderForm :: MyRecord -> Html
renderForm myRecord = formFor myRecord [hsx|
...
{(textField #foo)}
...
{submitButton}
|]
I wish to have something like:
{showMoneyAmount <$> (textField #foo)}
or:
{(textField #foo){formatValue = showMoneyAmount}}
Any ideas?