Membership Fee 6 - UI Components & LiveViews closes #280 #304
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()
|
@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 """
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue