{"id":22239941,"url":"https://github.com/macmotp/money","last_synced_at":"2025-10-07T13:33:38.478Z","repository":{"id":179791319,"uuid":"663855914","full_name":"macmotp/money","owner":"macmotp","description":"PHP Library to handle Money","archived":false,"fork":false,"pushed_at":"2024-09-30T02:40:47.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-05T11:44:58.176Z","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/macmotp.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":".github/contributing.md","funding":".github/funding.yml","license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"macmotp"}},"created_at":"2023-07-08T09:23:51.000Z","updated_at":"2024-09-30T02:40:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"46065f8a-a1bf-499e-9aa3-ae1e652fe6cb","html_url":"https://github.com/macmotp/money","commit_stats":null,"previous_names":["macmotp/money"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/macmotp/money","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmotp%2Fmoney","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmotp%2Fmoney/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmotp%2Fmoney/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmotp%2Fmoney/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macmotp","download_url":"https://codeload.github.com/macmotp/money/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmotp%2Fmoney/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267441248,"owners_count":24087771,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-03T03:27:49.097Z","updated_at":"2025-10-07T13:33:33.453Z","avatar_url":"https://github.com/macmotp.png","language":"PHP","funding_links":["https://github.com/sponsors/macmotp"],"categories":[],"sub_categories":[],"readme":"# Light Money Handler\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/macmotp/money.svg)](https://packagist.org/packages/macmotp/money)\n[![Total Downloads](https://img.shields.io/packagist/dt/macmotp/money.svg)](https://packagist.org/packages/macmotp/money)\n\n**Library to Handle Money and Currencies in PHP, simple and light**\n\nUseful for any ecommerce, fintech, or any app that requires 💰.\n\n## Requirements\n- PHP \u003e= 8.2\n\n## Installation\n\nInstall the package via composer:\n\n```bash\ncomposer require macmotp/money\n```\n\n## Usage\n\n### Create Money objects\n``` php\nuse Macmotp\\Money;\nuse Macmotp\\Support\\CurrencyCode;\n\n// Amounts are always in cents (or lowest minor unit)!\n$amount = 100;\n\n// All Currencies adopt ISO 4217 standard\n$currency = CurrencyCode::USD;\n\n// Create the object\n$money = new Money($amount, $currency);\n\n// Alternative methods\n$money = new Money($amount, 'USD');\n$money = Money::make($amount, $currency);\n\necho $money-\u003eprint();\n\n// (string) '1.00$'\n\n// Another example with Vietnamese Dong\n$money = new Money(10000, CurrencyCode::VND);\n\necho $money-\u003eprint();\n\n// (string) '10 000₫'\n\n```\n#### List of basic methods\n- `getAmount()`: return the amount in cents;\n- `getAmountForHumans()`: return the amount in decimals;\n- `getCurrencyCode()`: return the currency code;\n- `getCurrencySymbol()`: return the currency symbol;\n- `getCurrency()`: return the currency object (as Currency implementation, not as string);\n- `clone()`: clone the entire object;\n- `zero()`: set the amount to zero;\n\n_If you want to print any of the currency properties, check the Format class._\n_For example: if you want to get the currency code, you can run `$money-\u003egetCurrencyCode()`_\n\n### Print Money (on the screen, not for real)\n``` php\nuse Macmotp\\Money;\nuse Macmotp\\Support\\CurrencyCode;\n\n$money = new Money(12345, CurrencyCode::USD);\n\n// Default format based on each currency\n\necho $money-\u003eprint();\n\n// (string) '123.45$'\n\n// Override the default\n\necho $money-\u003ewithCode() \n           -\u003ewithSpace()\n           -\u003ewithoutDecimals()\n           -\u003eprint();\n\n// (string) '123 USD'\n```\n\n#### List of methods for printing\n- `toArray()`: convert the object into array;\n- `getCurrency()-\u003etoArray()`: convert the currency object into array;\n- `withSymbol()`: print the symbol and not the currency code;\n- `withoutSymbol()`: do not print neither symbol nor currency code;\n- `withCode()`: print the currency code and not the code;\n- `withoutCode()`: do not print neither symbol nor currency code;\n- `withSymbolOnLeft()`: print symbol on the left;\n- `withSymbolOnRight()`: print symbol on the right;\n- `withCodeOnLeft()`: print currency code on the left;\n- `withCodeOnRight()`: print currency code on the right;\n- `withSpace()`: print a space between the amount and the currency;\n- `withoutSpace()`: do not print a space between the amount and the currency;\n- `withoutDecimals()`: do not print decimals of the amount;\n- `withDecimalSeparator(string $decimalSeparator)`: override default decimal separator character;\n- `withThousandsSeparator(string $thousandsSeparator)`: override default thousands separator character;\n- `withNumberOfDecimals(int $numberOfDecimals)`: set the precision of the decimals;\n\n### Calculate with Money\n``` php\nuse Macmotp\\Money;\nuse Macmotp\\Support\\CurrencyCode;\n\n$moneyOne = new Money(200, CurrencyCode::USD);\n$moneyTwo = new Money(300, CurrencyCode::USD);\n\necho $moneyOne-\u003eadd($moneyTwo);\n\n// new Money(500, CurrencyCode::USD)\n```\n#### List of calculation methods\n- `add(Money $money)`;\n- `subtract(Money $money)`;\n- `multiply(float $factor, string $flat = '')`;\n- `divide(float $factor, string $flat = '')`;\n- `inPercentage(float $percentage, string $flat = '')`;\n- `absolute()`;\n\n### Aggregate Money\n``` php\nuse Macmotp\\Money;\nuse Macmotp\\Support\\CurrencyCode;\n\n$moneyOne = new Money(200, CurrencyCode::USD);\n$moneyTwo = new Money(300, CurrencyCode::USD);\n$moneyThree = new Money(400, CurrencyCode::USD);\n\necho Money::max($moneyOne, $moneyTwo, $moneyThree);\n\n// new Money(400, CurrencyCode::USD)\n\necho Money::avg($moneyOne, $moneyTwo, $moneyThree);\n\n// new Money(300, CurrencyCode::USD)\n```\n#### List of aggregation methods\n- `min(Money ...$money)`: return the minimum amount;\n- `max(Money ...$money)`: return the maximum amount;\n- `avg(Money ...$money)`: return the average amount;\n- `sum(Money ...$money)`: return the sum of all amounts;\n\n\n### Compare Money\n``` php\nuse Macmotp\\Money;\nuse Macmotp\\Support\\CurrencyCode;\n\n$moneyOne = new Money(200, CurrencyCode::USD);\n$moneyTwo = new Money(300, CurrencyCode::USD);\n\necho $moneyOne-\u003eisLessThan($moneyTwo);\n\n// (bool) true\n```\n#### List of comparison methods\n- `isSameCurrency(Money ...$money)`;\n- `isEqualTo(Money $money)`;\n- `isGreaterThan(Money $money)`;\n- `isGreaterThanOrEqualTo(Money $money)`;\n- `isLessThan(Money $money)`;\n- `isLessThanOrEqualTo(Money $money)`;\n- `isPositive()`;\n- `isNegative()`;\n- `isZero()`;\n- `isZeroOrPositive()`;\n- `isZeroOrNegative()`;\n\n### List of Currencies in the package\n``` php\nuse Macmotp\\Money;\n\n$list = Money::getAllCurrencies();\n// This will return a Illuminate\\Support\\Collection\n```\nThese are the implemented currencies:\n- `AED`: United Arab Emirates Dirham\n- `AFN`: Afghan Afghani\n- `ALL`: Albanian Lek\n- `AMD`: Armenian Dram\n- `ANG`: Netherlands Antillean Guilder\n- `AOA`: Angolan Kwanza\n- `ARS`: Argentine Peso\n- `AUD`: Australian Dollar\n- `AWG`: Aruban Florin\n- `AZN`: Azerbaijani Manat\n- `BAM`: Bosnia and Herzegovina Convertible Mark\n- `BBD`: Barbados Dollar\n- `BDT`: Bangladeshi Taka\n- `BGN`: Bulgarian Lev\n- `BHD`: Bahraini Dinar\n- `BIF`: Burundian Franc\n- `BMD`: Bermudian Dollar\n- `BND`: Brunei Dollar\n- `BOB`: Bolivian Boliviano\n- `BRL`: Brazilian Real\n- `BSD`: Bahamian Dollar\n- `BTC`: Bitcoin\n- `BTN`: Bhutanese Ngultrum\n- `BWP`: Botswana Pula\n- `BYN`: Belarusian Ruble\n- `BZD`: Belize Dollar\n- `CAD`: Canadian Dollar\n- `CDF`: Congolese Franc\n- `CHF`: Swiss Franc\n- `CLP`: Chilean Peso\n- `CNY`: Chinese Yuan - Renminbi\n- `COP`: Colombian Peso\n- `CRC`: Costa Rican Colón\n- `CUP`: Cuban Peso\n- `CVE`: Cape Verdean Escudo\n- `CZK`: Czech Koruna\n- `DJF`: Djiboutian Franc\n- `DKK`: Danish Krone\n- `DOP`: Dominican Peso\n- `DZD`: Algerian Dinar\n- `EGP`: Egyptian Pound\n- `ERN`: Eritrean Nakfa\n- `ETB`: Ethiopian Birr\n- `EUR`: Euro\n- `FJD`: Fijian Dollar\n- `FKP`: Falkland Islands Pound\n- `GBP`: British Pound\n- `GEL`: Georgian Lari\n- `GHS`: Ghanaian Cedi\n- `GIP`: Gibraltar Pound\n- `GMD`: Gambian Dalasi\n- `GNF`: Guinean Franc\n- `GTQ`: Guatemalan Quetzal\n- `GYD`: Guyanese Dollar\n- `HKD`: Hong Kong Dollar\n- `HNL`: Honduran Lempira\n- `HTG`: Haitian Gourde\n- `HUF`: Hungarian Forint\n- `IDR`: Indonesian Rupiah\n- `ILS`: Israeli New Shekel\n- `INR`: Indian Rupee\n- `IQD`: Iraqi Dinar\n- `IRR`: Iranian Rial\n- `ISK`: Icelandic Króna\n- `JMD`: Jamaican Dollar\n- `JOD`: Jordanian Dinar\n- `JPY`: Japanese Yen\n- `KES`: Kenyan Shilling\n- `KGS`: Kyrgyz Som\n- `KHR`: Cambodian Riel\n- `KMF`: Comorian Franc\n- `KPW`: North Korean Won\n- `KRW`: South Korean Won\n- `KWD`: Kuwaiti Dinar\n- `KYD`: Cayman Islands Dollar\n- `KZT`: Kazakhstani Tenge\n- `LAK`: Lao Kip\n- `LBP`: Lebanese Pound\n- `LKR`: Sri Lankan Rupee\n- `LRD`: Liberian Dollar\n- `LSL`: Lesotho Loti\n- `LYD`: Libyan Dinar\n- `MAD`: Moroccan Dirham\n- `MDL`: Moldovan Leu\n- `MGA`: Malagasy Ariary\n- `MKD`: Macedonian Denar\n- `MMK`: Burmese Kyat\n- `MNT`: Mongolian Tögrög\n- `MOP`: Macanese Pataca\n- `MRU`: Mauritanian Ouguiya\n- `MUR`: Mauritian Rupee\n- `MVR`: Maldivian Rufiyaa\n- `MWK`: Malawian Kwacha\n- `MXN`: Mexican Peso\n- `MYR`: Malaysian Ringgit\n- `MZN`: Mozambican Metical\n- `NAD`: Namibian Dollar\n- `NGN`: Nigerian Naira\n- `NIO`: Nicaraguan Córdoba\n- `NOK`: Norwegian Krone\n- `NPR`: Nepalese Rupee\n- `NZD`: New Zealand Dollar\n- `OMR`: Omani Rial\n- `PAB`: Panamanian Balboa\n- `PEN`: Peruvian Sol\n- `PGK`: Papua New Guinean Kina\n- `PHP`: Philippine Peso\n- `PKR`: Pakistani Rupee\n- `PLN`: Polish Złoty\n- `PYG`: Paraguayan Guaraní\n- `QAR`: Qatari Riyal\n- `RON`: Romanian Leu\n- `RSD`: Serbian Dinar\n- `RUB`: Russian Ruble\n- `RWF`: Rwandan Franc\n- `SAR`: Saudi Riyal\n- `SBD`: Solomon Islands Dollar\n- `SCR`: Seychellois Rupee\n- `SDG`: Sudanese Pound\n- `SEK`: Swedish Krona\n- `SGD`: Singapore Dollar\n- `SHP`: Saint Helena Pound\n- `SLE`: Sierra Leonean Leone\n- `SOS`: Somali Shilling\n- `SRD`: Surinamese Dollar\n- `SSP`: South Sudanese Pound\n- `STN`: São Tomé and Príncipe Dobra\n- `SYP`: Syrian Pound\n- `SZL`: Swazi Lilangeni\n- `THB`: Thai Baht\n- `TJS`: Tajikistani Somoni\n- `TMT`: Turkmenistani Manat\n- `TND`: Tunisian Dinar\n- `TOP`: Tongan Paʻanga\n- `TRY`: Turkish Lira\n- `TTD`: Trinidad and Tobago Dollar\n- `TWD`: New Taiwan Dollar\n- `TZS`: Tanzanian Shilling\n- `UAH`: Ukrainian Hryvnia\n- `UGX`: Ugandan Shilling\n- `USD`: United States Dollar\n- `UYU`: Uruguayan Peso\n- `UZS`: Uzbekistani Sum\n- `VES`: Venezuelan Sovereign Bolívar\n- `VND`: Vietnamese Đồng\n- `VUV`: Vanuatu Vatu\n- `WST`: Samoan Tālā\n- `XAF`: Central African CFA Franc\n- `XCD`: Eastern Caribbean Dollar\n- `XOF`: West African CFA Franc\n- `XPF`: CFP Franc\n- `YER`: Yemeni Rial\n- `ZAR`: South African Rand\n- `ZMW`: Zambian Kwacha\n- `ZWG`: Zimbabwe Gold\n\n_If you want to add another currency, please open an issue._\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [changelog](changelog.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [contributing](.github/contributing.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](.github/security.md) on how to report security vulnerabilities.\n\n## Credits\n\n- [Marco Gava](https://github.com/macmotp)\n\n## License\n\nThe MIT License (MIT). Please see [License File](license.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacmotp%2Fmoney","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacmotp%2Fmoney","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacmotp%2Fmoney/lists"}