elixirmoney / money

Elixir library for working with Money safer, easier, and fun... Is an interpretation of the Fowler's Money pattern in fun.prog.
https://hex.pm/packages/money/
MIT License
826 stars 139 forks source link

Fix to_string to use the minus_sign_first option #181

Closed joshlarson closed 2 years ago

joshlarson commented 2 years ago

What

Before PR:

Money.new(-1000, "EUR") |> Money.to_string() # "-€10.00", new behavior, correct
Money.new(-1000, "EUR") |> Money.to_string(minus_sign_first: false) # "-€10.00", option is ignored

After PR:

Money.new(-1000, "EUR") |> Money.to_string() # "-€10.00", still correct
Money.new(-1000, "EUR") |> Money.to_string(minus_sign_first: false) # "€-10.00", option is now being respected

Why

A previous PR - https://github.com/elixirmoney/money/pull/173 - changed how negative values are rendered, and added an option called minus_sign_first to the documentation. That flag was being ignored.

This change updates Money.to_string to use that flag, so that users can optionally get backwards compatibility with older versions of Money.

Nitrino commented 2 years ago

@joshlarson Thanks ❤️