{"id":15366947,"url":"https://github.com/fortis/moneyobject","last_synced_at":"2025-04-15T12:33:36.078Z","repository":{"id":62506662,"uuid":"103095042","full_name":"fortis/moneyobject","owner":"fortis","description":"A PHP library providing immutable 💰 Money value object","archived":false,"fork":false,"pushed_at":"2021-02-14T20:21:08.000Z","size":32,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T20:12:14.573Z","etag":null,"topics":["bcmath","currency","gmp","money"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fortis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-11T05:51:31.000Z","updated_at":"2021-02-14T20:21:10.000Z","dependencies_parsed_at":"2022-11-02T12:45:42.550Z","dependency_job_id":null,"html_url":"https://github.com/fortis/moneyobject","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortis%2Fmoneyobject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortis%2Fmoneyobject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortis%2Fmoneyobject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortis%2Fmoneyobject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fortis","download_url":"https://codeload.github.com/fortis/moneyobject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249072389,"owners_count":21208179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bcmath","currency","gmp","money"],"created_at":"2024-10-01T13:20:30.886Z","updated_at":"2025-04-15T12:33:36.046Z","avatar_url":"https://github.com/fortis.png","language":"PHP","readme":"# moneyobject\n\n[![Travis](https://img.shields.io/travis/fortis/moneyobject.svg?branch=master)](https://travis-ci.org/fortis/moneyobject)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fortis/moneyobject/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fortis/moneyobject/?branch=master)\n[![Coveralls](https://img.shields.io/coveralls/fortis/moneyobject/master.svg)](https://coveralls.io/github/fortis/moneyobject?branch=master)\n[![Packagist](https://img.shields.io/packagist/l/fortis/moneyobject.svg)](https://packagist.org/packages/fortis/moneyobject)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ffortis%2Fmoneyobject.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Ffortis%2Fmoneyobject?ref=badge_shield)\n\nA PHP library providing immutable Money value object with arbitrary-precision and solution for floating point rounding errors.\n\nWhat do you think will be printed in the example below?\n``` php\nprint (36 - 35.99) === 0.01 ? '✅ equals' : 'not equals 😈';\n```\nActually `not equals 😈` . You can try [https://ideone.com/2UQlBF](https://ideone.com/2UQlBF). \n\n\u003e Squeezing infinitely many real numbers into a finite number of bits requires an approximate representation. Although there are infinitely many integers, in most programs the result of integer computations can be stored in 32 bits. In contrast, given any fixed number of bits, most calculations with real numbers will produce quantities that cannot be exactly represented using that many bits. Therefore the result of a floating-point calculation must often be rounded in order to fit back into its finite representation. This rounding error is the characteristic feature of floating-point computation.\n\u003e\n\u003e *-- [Oracle](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)*\n\n## Install\n\nInstall directly from command line using Composer\n``` bash\ncomposer require fortis/moneyobject\n```\n\n## QuickStart\n\n#### Currency code validation\n``` php\n$money = new Money(100, 'USF'); // throws InvalidCurrencyException\n```\n\n#### Create Money instance\n``` php\n$money = Money::USD(100.20);                       // 100.20 USD. Short syntax with autocomplete.\n$money = new Money(100.20, CurrencyCode::USD);     // 100.20 USD  \n$money = Money::create(100.20, CurrencyCode::USD); // 100.20 USD\n```\n\n#### Get currency\n``` php\n$money-\u003egetCurrency()-\u003egetCode(); // USD\n```\n\n#### Get amount\n``` php\n$money-\u003egetAmount()-\u003etoFloat();   // 100.20\n```\n\n#### Multiply: 100.20 * 2\n``` php\n$money-\u003emultiply(2)\n      -\u003egetAmount()-\u003etoFloat(); // 200.40\n```\n\n#### Divide: 100.20 / 2\n``` php\n$money-\u003edivide(Money::USD(2))\n      -\u003egetAmount()-\u003etoFloat(); // 50.10\n```\n\n#### Plus: 100.20 + 2.5\n``` php\n$money-\u003eplus(Money::USD(2.5))\n      -\u003egetAmount()-\u003etoFloat(); // 102.70\n```\n\n#### Minus: 100.20 - 0.5\n``` php\n$money-\u003eminus(Money::USD(0.5))\n      -\u003egetAmount()-\u003etoFloat(); // 99.70\n```\n\n#### Minus: 36 - 35.99      \n``` php\nMoney::USD(36)-\u003eminus(Money::USD(35.99))\n              -\u003egetAmount()-\u003etoFloat(); // 0.01\n```\n\n#### Minus: 36 - 35.99        \n``` php\nMoney::USD(36)-\u003eminus(35.99)\n              -\u003egetAmount()-\u003etoFloat(); // 0.01\n```\n\n#### Convert USD to EUR\n```bash\n$ composer require florianv/swap php-http/message php-http/guzzle6-adapter\n```\n\n``` php\n$swap = (new SwapBuilder())\n    -\u003eadd('fixer')\n    -\u003ebuild();\n$converter = new Converter($swap);\n$usd50 = Money::USD(50);\n$result = $converter-\u003econvert($usd50, Currency::EUR());\n```\n\n## Credits\n\n- [Florian Voutzinos](https://github.com/florianv)\n\n\n## License\n\nmoneyobject is licensed under the MIT license.\n\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Ffortis%2Fmoneyobject.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Ffortis%2Fmoneyobject?ref=badge_large)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortis%2Fmoneyobject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffortis%2Fmoneyobject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortis%2Fmoneyobject/lists"}