diff --git a/lib/mv_web/helpers/membership_fee_helpers.ex b/lib/mv_web/helpers/membership_fee_helpers.ex index ea866e4..0d2c3d3 100644 --- a/lib/mv_web/helpers/membership_fee_helpers.ex +++ b/lib/mv_web/helpers/membership_fee_helpers.ex @@ -25,10 +25,25 @@ defmodule MvWeb.Helpers.MembershipFeeHelpers do """ @spec format_currency(Decimal.t()) :: String.t() def format_currency(%Decimal{} = amount) do - # Use German format: comma as decimal separator - amount_str = Decimal.to_string(amount, :normal) - amount_str = String.replace(amount_str, ".", ",") - "#{amount_str} €" + # Use German format: comma as decimal separator, always 2 decimal places + # Normalize to 2 decimal places + normalized = Decimal.round(amount, 2) + 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 @doc """