Skip to content

Add Decimal support to Money.Ecto.Composite.Type#235

Open
EdoardoLopez wants to merge 1 commit intoelixirmoney:masterfrom
EdoardoLopez:ecto_decimal_composite_type
Open

Add Decimal support to Money.Ecto.Composite.Type#235
EdoardoLopez wants to merge 1 commit intoelixirmoney:masterfrom
EdoardoLopez:ecto_decimal_composite_type

Conversation

@EdoardoLopez
Copy link

Addresses issue #234 by adding support for Decimal in the load/1 function of Money.Ecto.Composite.Type. This change is similar to the resolution in issue #219, which also involved enhancing the load/1 function for better type handling.

- Implement support for `Decimal` in the `load/1` function of `Money.Ecto.Composite.Type`.
end
@spec load({integer() | Decimal.t(), atom() | String.t()}) :: {:ok, Money.t()}
def load({amount, currency}) when is_integer(amount), do: {:ok, Money.new(amount, currency)}
def load({%Decimal{} = amount, currency}), do: {:ok, amount |> Decimal.to_integer() |> Money.new(currency)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decimal.to_integer is not a safe conversion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants