{"action":"closed","issue":{"url":"https://api.github.com/repos/moneyphp/money/issues/272","repository_url":"https://api.github.com/repos/moneyphp/money","labels_url":"https://api.github.com/repos/moneyphp/money/issues/272/labels{/name}","comments_url":"https://api.github.com/repos/moneyphp/money/issues/272/comments","events_url":"https://api.github.com/repos/moneyphp/money/issues/272/events","html_url":"https://github.com/moneyphp/money/issues/272","id":176179739,"number":272,"title":"Conversion with different subunits, not working as expected","user":{"login":"muteor","id":305164,"avatar_url":"https://avatars.githubusercontent.com/u/305164?v=3","gravatar_id":"","url":"https://api.github.com/users/muteor","html_url":"https://github.com/muteor","followers_url":"https://api.github.com/users/muteor/followers","following_url":"https://api.github.com/users/muteor/following{/other_user}","gists_url":"https://api.github.com/users/muteor/gists{/gist_id}","starred_url":"https://api.github.com/users/muteor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muteor/subscriptions","organizations_url":"https://api.github.com/users/muteor/orgs","repos_url":"https://api.github.com/users/muteor/repos","events_url":"https://api.github.com/users/muteor/events{/privacy}","received_events_url":"https://api.github.com/users/muteor/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-10T13:30:20Z","updated_at":"2016-10-03T09:07:52Z","closed_at":"2016-10-03T09:07:52Z","body":"This is for the 3.0 beta.\r\n\r\nWhen converting between two currencies that have different subunits, the conversion is not returning the correct amount.\r\n\r\nHere is test case added to `CurrencyPairSpec.php`\r\n\r\n```php\r\nfunction it_converts_correctly_when_currencies_have_different_subunits() {\r\n    $this->beConstructedWith(new Currency('GBP'), new Currency('BHD'), 0.5);\r\n\r\n    $money = new Money(100, new Currency('GBP'));\r\n\r\n    $resultMoney = $this->convert($money);\r\n\r\n    $resultMoney->shouldHaveType(Money::class);\r\n    $resultMoney->getAmount()->shouldBeLike(500);\r\n    $resultMoney->getCurrency()->getCode()->shouldReturn('BHD');\r\n}\r\n```\r\n\r\nRunning this, `$resultMoney` has value of `50` where it should be `500` because `BHD` has subunit of `1000` not `100`.\r\n\r\nThis can be fixed by doing `((subunit_to / subunit_from) * amount) * rate` when doing the conversion. So in this example `((1000 / 100) * 100) * 0.5 = 500` which is `500 fils` or `0.5  dinar` (http://www.xe.com/currencyconverter/convert/?Amount=1&From=GBP&To=BHD). \r\n\r\nI had a quick look at the `convert` method but wasn't sure how you would like getting the subunit value into that method, looks like we would need to add a dependency on currencies."}}
{"actor":{"display_login":"frederikbosch"}}