{"id":18668139,"url":"https://github.com/eonx-com/currencies","last_synced_at":"2025-12-13T10:01:44.266Z","repository":{"id":56978338,"uuid":"127831121","full_name":"eonx-com/currencies","owner":"eonx-com","description":"Package providing helpers around currencies","archived":false,"fork":false,"pushed_at":"2020-03-27T03:50:56.000Z","size":157,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-27T18:24:38.890Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eonx-com.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-03T01:05:17.000Z","updated_at":"2022-09-08T23:23:24.000Z","dependencies_parsed_at":"2022-08-21T08:10:57.448Z","dependency_job_id":null,"html_url":"https://github.com/eonx-com/currencies","commit_stats":null,"previous_names":["loyaltycorp/currencies"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fcurrencies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fcurrencies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fcurrencies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fcurrencies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eonx-com","download_url":"https://codeload.github.com/eonx-com/currencies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239498550,"owners_count":19648905,"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":["library"],"created_at":"2024-11-07T08:41:31.964Z","updated_at":"2025-11-06T16:30:27.439Z","avatar_url":"https://github.com/eonx-com.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Currencies\n\nThis library allows currencies to be found by [ISO4217](https://en.wikipedia.org/wiki/ISO_4217) code or numeric identifier and formatted for display based on different locales.\n\nThis library comes in three main parts: currencies, locales and a translator.\n\n## Currencies\n\nCurrencies are simple files made up of:\n\n| Property | Description |\n|----------|-------------|\n| Minor unit | The number of decimal places the currency uses, e.g. 2 for Australian Dollar |\n| Name | The currency name, e.g. Australian Dollar |\n| Numeric code | The ISO4217 numeric code, e.g. 036 for Australian Dollar |\n| Symbol   | The UTF-8 currency symbol, e.g. $ |\n\nThe currency class name is the ISO4217 alpha code in PSR-2 format, e.g. `Aud` for Australian Dollar.\n\n### Finding a currency\n\nYou can find a currency using the `ISO4217` class. This class provides two methods:\n\n| Method | Description |\n|--------|-------------|\n| `find($code): CurrencyInterface` | Find a currency by alpha* or numeric code |\n| `getSupportedAlphaCodes(): array` | Get a list of supported alpha codes |\n\n\u003csup\u003e* Alpha code is case insensitive\u003c/sup\u003e\n\n**Note:** Not all currencies are currently supported, more currencies will be added as soon as possible, optionally you can open a pull request to add currencies you require.\n\n### Working with a currency\n\nIf a currency is successfully found you will recieve a currency object back with the following methods:\n\n| Method | Description |\n|----------|-------------|\n| `getAlphaCode(): string` | Get the alpha code for the currency |\n| `getMinorUnit(): int` | Get the number of decimal places the currency uses |\n| `getName(): string` | Get full name for the currency |\n| `getNumericCode(): string` | Get the ISO4217 numeric code for the currency |\n| `getCurrencySymbol(): string`   | Get the UTF-8 symbol for the currency |\n\n## Locales\n\nLocales are also simple files made up of:\n\n| Property | Description |\n|----------|-------------|\n| Identifier | The IETF language tag of the locale, e.g. en-AU for Australian English |\n| Currency format | How to format a currency using symbol replacement, e.g. '-¤ #' for Australian English |\n| Decimal separator | How decimals are represented in numeric displays, e.g. period for Australian English |\n| Negative symbol | The negative symbol used by this locale, e.g. hyphen for Austrlaian English |\n| Numeric format | How to format a numeric value using symbol replacement, e.g. '-#' for Australian English |\n| Thousands separator | The separator used to group thousands together, e.g. comma for Australian English |\n\n### Why not php-intl?\n\nThis code seems to duplicate what php-intl provides with the [NumberFormatter class](http://php.net/manual/en/class.numberformatter.php) however this extension works differently on different operating systems and locales which causes formatted numbers and currencies to be inconsistent. The [symfony/intl](http://symfony.com/doc/current/components/intl.html) package only provides support for en-US or falls back to `php-intl` if it's installed which causes the same issues. \n\nThis library provides consistenty across all operating systems independently of `php-intl` when it comes to formatting numbers or currencies for display.\n\n### Finding a locale\n\nYou can find a currency using the `Translator` class. This class provides two methods:\n\n| Method | Description |\n|--------|-------------|\n| `find($code): LocaleInterface` | Find a locale by IETF language code* |\n| `getSupportedLocales(): array` | Get a list of supported IETF language codes |\n\n\u003csup\u003e* IETF is case insensitive and ignores special characters: en-au, en_AU, enAu and en((au will all resolve correctly\u003c/sup\u003e\n\n**Note:** Not all locales are currently supported, more locales will be added as soon as possible, optionally you can open a pull request to add locales you require.\n\n### Working with a locale\n\nIf a locale is successfully found you will recieve a locale object back with the following method:\n\n| Method | Description |\n|----------|-------------|\n| `getIdentifier(): string` | Get the IETF language code for the current locale |\n\n## Formatting\n\nThe real use of this class is to format numbers and currencies based on locale, this is done via for `Formatter` class which provides four methods:\n\n| Method | Description |\n|--------|-------------|\n| `currency(string $locale): string` | Get the amount formatted using the precision and symbol from the currency displayed based on an IETF locale language code |\n| `decimal(): string` | Get the amount formatted using the precision from the currency, e.g. 2 decimal places for Australian Dollar |\n| `numeric(string $locale): string` | Get the amount formatted using the precision from the currency displayed based on an IETF locale language code |\n\nWhen instantiating the formatter an amount and ISO4217 alpha or numeric code must be passed to the constructor.\n\n```\n/**\n * Format a currency based on locale\n */\n\n// Create formatter based on bitcoin with negative value\n$formatter = new \\EoneoPay\\Currencies\\Formatter('-1.051', 'xbt');\n\n// Australia\necho $formatter-\u003ecurrency('en-AU'); // -฿1,601.05100000\n\n// China\necho $formatter-\u003ecurrency('zh-CN'); // -฿ 1601.05100000\n\n// France\necho $formatter-\u003ecurrency('fr-FR'); // -1 601,05100000 ฿\n\n// Netherlands\necho $formatter-\u003ecurrency('nl-NL'); // ฿ -1.601,05100000\n\n// Oman\necho $formatter-\u003ecurrency('ar-OM'); // ؜฿ ؜-١٬٦٠١٫٠٥١٠٠٠٠٠\n\n```\n```\n/**\n * Format a number based on locale\n */\n \n// Create formatter based on bitcoin with positive value\n$formatter = new \\EoneoPay\\Currencies\\Formatter('1.051', 'xbt');\n\n// Australia\necho $formatter-\u003enumeric('en-AU'); // 1,601.05100000\n\n// China\necho $formatter-\u003enumeric('zh-CN'); // 1601.05100000\n\n// France\necho $formatter-\u003enumeric('fr-FR'); // 1 601,05100000\n\n// Netherlands\necho $formatter-\u003enumeric('nl-NL'); // 1.601,05100000\n\n// Oman\necho $formatter-\u003enumeric('ar-OM'); // ؜١٬٦٠١٫٠٥١٠٠٠٠٠\n```\n\n**Note:** Arabic may not be displayed correctly due to RTL formatting of the output.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feonx-com%2Fcurrencies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feonx-com%2Fcurrencies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feonx-com%2Fcurrencies/lists"}