Changelog for Money v2.0.1
This is the changelog for Money v2.0.1 released on January 16th, 2017. For older changelogs please consult the release tag on GitHub
Bug Fixes
Phoenix.HTML.Safe
protocol implementation correctly returns a formatted string, not an{:ok, string}
tuple. Closes #45.
Changelog for Money v2.0.0
Breaking Changes
- The function
Money.new/2
no longer supports afloat
amount. The new functionMoney.from_float/2
is introduced. The factory functionMoney.new/2
previously supported afloat
amount as a parameter. There are many well-documented issues with float. Although a float with a precision of no more than 15 digits will convert (and round-trip) without loss of precision there is a real possibility that the upstream calculations that produced the float will have introduced rounding or precision errors. CallingMoney.new/2
with a float amount will return an error tuple:
{:error, {
Money.InvalidAmountError,
"Float amounts are not supported in new/2 due to potenial rounding " <>
"and precision issues. If absolutely required, use Money.from_float/2"}}
- Remove support for
Money
tuples inMoney.Ecto.Composite.Type
andMoney.Ecto.Map.Type
. Previously there has been support for dumpingMoney
in a tuple format. This support has now been removed and allMoney
operations should be based on theMoney.t
struct.
Enhancements
Add
Money.from_float/2
to create aMoney
struct from a float and a currency code. This function is named to make it clear that we risk losing precision due to upstream rounding errors. According to the standard and experimentation, floats of up to 15 digits of precision will round trip without error. Thereforefrom_float/2
will check the precision of the number and return an error if the precision is greater than 15 since the correctness of the number cannot be verified beyond that.Add
Money.from_float!/2
which is likefrom_float/2
but raises on errorFormatted the text the with the Elixir 1.6 code formatter