{"id":22092098,"url":"https://github.com/krakphp/money","last_synced_at":"2025-03-23T23:44:53.257Z","repository":{"id":57009031,"uuid":"57080995","full_name":"krakphp/money","owner":"krakphp","description":"Money manipulation library","archived":false,"fork":false,"pushed_at":"2017-06-26T09:15:35.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T06:52:19.754Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/krakphp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-04-25T22:39:28.000Z","updated_at":"2016-04-25T22:40:16.000Z","dependencies_parsed_at":"2022-08-21T14:50:50.865Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/money","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fmoney","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fmoney/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fmoney/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fmoney/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/money/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186923,"owners_count":20574554,"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":[],"created_at":"2024-12-01T03:08:19.725Z","updated_at":"2025-03-23T23:44:53.234Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Money\n\nSimple money manipulation library which uses bcmath to manipulate money values appropriately.\n\n## Install\n\nInstall via composer at `krak/money`\n\n## Usage\n\n```php\n\u003c?php\n\nuse Krak\\Money;\n\n$calc = Money\\calc($precision = 2);\n$res = $calc-\u003eadd('1.00', '2.00');\n$res = $calc-\u003emul($res, 2);\n```\n\n## API\n\n### calc($precision = 2)\n\nReturns a cached instance of the BCMathCalculator. Set the precision to higher if you need to do any multiplications or divisions\nwith the money that might require extra precision.\n\n### preciseCalc()\n\nReturns a cached instance of the FloatCalculator. Use this calculator if you have to do any intense money calculations like calculate compounding interest where you need a LOT of precision. Once done, you should then use the `money\\f` to format the resulting money as proper money.\n\n### f($money)\n\nFormat the money by rounding it to two decimal places and returning a properly formatted money string of `\\d+\\.\\d{2}`\n\n### interface Calculator\n\n```php\n\u003c?php\n\ninterface Calculator {\n    public function add($a, $b);\n    public function sub($a, $b);\n    public function mul($a, $b);\n    public function div($a, $b);\n    public function cmp($a, $b);\n}\n```\n\nThese methods are fairly self explanatory, the `cmp` method will return 0 if `$a` and `$b` are equal, \u003e 0 if `$a` is \u003e `$b` and \u003c 0 else.\n\n### abstract class AbstractCalculator\n\n```php\n\u003c?php\n\nabstract class AbstractCalculator implements Calculator {\n    public function sum(...$args);\n    public function diff(...$args);\n    public function quot(...$args);\n    public function prod(...$args);\n    /** returns the max value of the set */\n    public function max(...$args);\n    /** returns the min value of the set */\n    public function min(...$args);\n    /** returns true if $a \u003c $b */\n    public function lt($a, $b);\n    /** returns true if $a \u003c= $b */\n    public function lte($a, $b);\n    /** returns true if $a \u003e $b */\n    public function gt($a, $b);\n    /** returns true if $a \u003e= $b */\n    public function gte($a, $b);\n    /** returns true if $a == $b */\n    public function eq($a, $b);\n    /** returns true if $a != $b */\n    public function neq($a, $b);\n\n    abstract public function add($a, $b);\n    abstract public function sub($a, $b);\n    abstract public function mul($a, $b);\n    abstract public function div($a, $b);\n    abstract public function cmp($a, $b);\n}\n```\n\nAny calculator should extend this class instead of directly implementing the `Calculator` interface so that it can have these extra methods.\n\nEach method simply will find the sum, difference, quotient, product, max, or min of the set of args. They delegate the actual calculations to the abstract functions.\n\n## Tests\n\n```\nmake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fmoney","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Fmoney","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fmoney/lists"}