fix: remove unused variable in format_currency function

- Replace unused amount_str variable with normalized_str
- Ensure consistent variable naming throughout function
This commit is contained in:
Moritz 2025-12-16 11:59:40 +01:00
parent 8ed9adeea0
commit e8e47fd92a
Signed by: moritz
GPG key ID: 1020A035E5DD0824

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 """