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:
parent
8ed9adeea0
commit
e8e47fd92a
1 changed files with 19 additions and 4 deletions
|
|
@ -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 """
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue