Membership Fee 6 - UI Components & LiveViews closes #280 #304

Open
moritz wants to merge 65 commits from feature/280_membership_fee_ui into main
Showing only changes of commit e8e47fd92a - Show all commits

View file

@ -25,10 +25,25 @@ defmodule MvWeb.Helpers.MembershipFeeHelpers do
""" """
@spec format_currency(Decimal.t()) :: String.t() @spec format_currency(Decimal.t()) :: String.t()
def format_currency(%Decimal{} = amount) do def format_currency(%Decimal{} = amount) do
# Use German format: comma as decimal separator # Use German format: comma as decimal separator, always 2 decimal places
amount_str = Decimal.to_string(amount, :normal) # Normalize to 2 decimal places
amount_str = String.replace(amount_str, ".", ",") normalized = Decimal.round(amount, 2)
"#{amount_str}" normalized_str = Decimal.to_string(normalized, :normal)
normalized_str = String.replace(normalized_str, ".", ",")
# Ensure 2 decimal places
case String.split(normalized_str, ",") do
[int_part, dec_part] when byte_size(dec_part) == 1 ->
"#{int_part},#{dec_part}0 €"
[int_part, dec_part] when byte_size(dec_part) == 2 ->
"#{int_part},#{dec_part}"
[int_part] ->
"#{int_part},00 €"
_ ->
"#{normalized_str}"
end
end end
@doc """ @doc """