Hi
I am trying to format currency (eg, 5.32) in liveview template, currently I am using Decimal package to format the number in template like so:
<span class="ml-2"><%= Decimal.new(cashflow_entry.amount) |> Decimal.round(2) %></span>
The output is fine. but few questions came out of my mind:
-
Does it affect change tracking? change tracking still work?
-
Is there anyway to specify in Phoenix Ecto schema, so the 2 decimal places is the default for display. according to my understanding, changeset is for change, what about display one?
I am thinking → define once then forget about it -
if the second idea doesn’t exists, i guess it would be better to create a custom function to format the decimal right? like
format_decimal(5.32)
for use in template.
I am new to phoenix ecto and came from Django, django provide built-in function to format such number, therefore I am trying to accomplish the same.