{"action":"created","issue":{"url":"https://api.github.com/repos/mathiasverraes/money/issues/107","labels_url":"https://api.github.com/repos/mathiasverraes/money/issues/107/labels{/name}","comments_url":"https://api.github.com/repos/mathiasverraes/money/issues/107/comments","events_url":"https://api.github.com/repos/mathiasverraes/money/issues/107/events","html_url":"https://github.com/mathiasverraes/money/issues/107","id":107697255,"number":107,"title":"add 'unitsToString' function to Money\\Money","user":{"login":"johanwilfer","id":1157420,"avatar_url":"https://avatars.githubusercontent.com/u/1157420?v=3","gravatar_id":"","url":"https://api.github.com/users/johanwilfer","html_url":"https://github.com/johanwilfer","followers_url":"https://api.github.com/users/johanwilfer/followers","following_url":"https://api.github.com/users/johanwilfer/following{/other_user}","gists_url":"https://api.github.com/users/johanwilfer/gists{/gist_id}","starred_url":"https://api.github.com/users/johanwilfer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanwilfer/subscriptions","organizations_url":"https://api.github.com/users/johanwilfer/orgs","repos_url":"https://api.github.com/users/johanwilfer/repos","events_url":"https://api.github.com/users/johanwilfer/events{/privacy}","received_events_url":"https://api.github.com/users/johanwilfer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-22T11:38:13Z","updated_at":"2015-11-17T23:27:08Z","closed_at":null,"body":"For legacy systems I need to convert to/from floats. To convert I do the following:\r\n```php\r\nuse Money\\Money;\r\nuse Money\\Currency;\r\n$float = 123.34;\r\n$money = new Money(Money::stringToUnits((string)$float), new Currency('USD'));\r\nvar_dump($money);\r\n/*\r\nobject(Money\\Money)#2 (2) {\r\n  [\"amount\":\"Money\\Money\":private]=>\r\n  int(12334)\r\n  [\"currency\":\"Money\\Money\":private]=>\r\n  object(Money\\Currency)#3 (1) {\r\n    [\"name\":\"Money\\Currency\":private]=>\r\n    string(3) \"USD\"\r\n  }\r\n}\r\n*/\r\n\r\n$float = $money->getAmount() / 100;\r\nvar_dump($float);\r\n/*\r\nfloat(123.34)\r\n*/\r\n```\r\n\r\nFor example money_format() expects the parameter to be a float: http://php.net/manual/en/function.money-format.php\r\n\r\nShouldn't it make sense to have a unitsToString() in `Money\\Money`? Maybe even\r\nunitsToFloat() and floatToUnits() .\r\n\r\nI can create a pull-request for this if you would consider including this change.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/mathiasverraes/money/issues/comments/157543816","html_url":"https://github.com/mathiasverraes/money/issues/107#issuecomment-157543816","issue_url":"https://api.github.com/repos/mathiasverraes/money/issues/107","id":157543816,"user":{"login":"camspiers","id":51294,"avatar_url":"https://avatars.githubusercontent.com/u/51294?v=3","gravatar_id":"","url":"https://api.github.com/users/camspiers","html_url":"https://github.com/camspiers","followers_url":"https://api.github.com/users/camspiers/followers","following_url":"https://api.github.com/users/camspiers/following{/other_user}","gists_url":"https://api.github.com/users/camspiers/gists{/gist_id}","starred_url":"https://api.github.com/users/camspiers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camspiers/subscriptions","organizations_url":"https://api.github.com/users/camspiers/orgs","repos_url":"https://api.github.com/users/camspiers/repos","events_url":"https://api.github.com/users/camspiers/events{/privacy}","received_events_url":"https://api.github.com/users/camspiers/received_events","type":"User","site_admin":false},"created_at":"2015-11-17T23:27:08Z","updated_at":"2015-11-17T23:27:08Z","body":"https://github.com/sebastianbergmann/money/blob/master/src/Money.php#L131-L134\r\nhttps://github.com/sebastianbergmann/money-intl-formatter/blob/master/src/IntlFormatter.php\r\n\r\nWhen displaying currency values you should take into account locale as well. The php NumberFormatter class takes care of this. You should also take into account the currencies subunit when doing the division. For example with Yen you should be string 100 Yen as `int(100)` and therefore when you format and display you shouldn't be dividing by 100.\r\n\r\nhttps://en.wikipedia.org/wiki/Denomination_(currency)#Subunit_and_super_unit"}}