moneyphp / money

PHP implementation of Fowler's Money pattern.
http://moneyphp.org
MIT License
4.57k stars 440 forks source link

ratioOf works incorrect for currencies with different minor units #732

Closed smelesh closed 1 year ago

smelesh commented 1 year ago

ratioOf assumes that the given amount has the same minor units as the current amount, otherwise the result is incorrect:

Money::EUR(20_00)->ratioOf(Money::JPY(1000))

expected: 0.02 actual: 2.00

Probably ratioOf should throw an exception when currencies don't match to avoid unexpected results.

peterdevpl commented 1 year ago

Yes, it makes sense for ratioOf to throw an exception on unmatched currencies, especially that mod already does that. I made a PR.