{"id":26509756,"url":"https://github.com/readysteady/monies","last_synced_at":"2026-02-18T20:08:10.735Z","repository":{"id":257811233,"uuid":"852695905","full_name":"readysteady/monies","owner":"readysteady","description":"Ruby gem for representing monetary values","archived":false,"fork":false,"pushed_at":"2025-01-02T13:08:12.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-10T13:49:17.050Z","etag":null,"topics":["money","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/monies","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/readysteady.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-05T09:00:34.000Z","updated_at":"2025-01-02T13:08:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"69ef628d-242b-400f-959b-aa182768185c","html_url":"https://github.com/readysteady/monies","commit_stats":null,"previous_names":["readysteady/monies"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fmonies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fmonies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fmonies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/readysteady%2Fmonies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/readysteady","download_url":"https://codeload.github.com/readysteady/monies/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244722706,"owners_count":20499151,"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":["money","ruby"],"created_at":"2025-03-21T01:36:10.267Z","updated_at":"2026-02-18T20:08:05.703Z","avatar_url":"https://github.com/readysteady.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# monies\n\n![Gem Version](https://badge.fury.io/rb/monies.svg)\n![Test Status](https://github.com/readysteady/monies/actions/workflows/test.yml/badge.svg)\n\n\nRuby gem for representing monetary values.\n\nPure Ruby—compatible with MRI/CRuby, JRuby, TruffleRuby, and Natalie.\n\n\n## Installation\n\nUsing Bundler:\n\n    $ bundle add monies\n\nUsing RubyGems:\n\n    $ gem install monies\n\n\n## Usage\n\nGetting started:\n\n```ruby\nrequire 'monies'\n\na = Monies(11, 'USD')\nb = Monies('22.22', 'USD') * 2\nc = Monies.parse('$33.44')\n\nputs Monies.format(a + b + c, symbol: true)\n```\n\n\n## Currencies\n\nCurrencies are represented as strings. Using [ISO 4217 currency codes](https://en.wikipedia.org/wiki/ISO_4217)\nis recommended for maximum interoperability, however there are no restrictions\non what strings you can use. For example:\n\n```ruby\nMonies(10, 'USD')\nMonies(10, 'BTC')\nMonies(10, 'GBX')\nMonies(10, 'X')\nMonies(10, 'LOL')\nMonies(10, 'Cubit')\nMonies(10, 'Latinum')\nMonies(10, 'sats')\n```\n\nIf your application primarily uses a single currency you can set a default currency:\n\n```ruby\nMonies.currency = 'USD'\n\nMonies(10)\n```\n\n\n## Arithmetic\n\nArithmetic is currency checked to prevent errors:\n\n```ruby\nMonies(1, 'USD') + Monies(1, 'RUB')  # raises Monies::CurrencyError\n```\n\nIf you need to sum amounts in different currencies you should first convert\nthem all to the same currency.\n\nDivision is limited to 16 decimal places by default, which ought to be enough\nfor everyone. If you need more accuracy you can use the #div method to specify\nthe maximum number of decimal places you want:\n\n```ruby\nMonies(1, 'USD').div(9, 100)\n```\n\nUse the #allocate method to split an amount into a number of smaller amounts:\n\n```ruby\ninstallments = Monies(1, 'USD').allocate(3, 2)\n```\n\n\n## Currency conversion\n\nUse the #convert method to convert instances to another currency:\n\n```ruby\nvalue = Monies('1.23', 'BTC')\n\nprice = Monies(100_000, 'USD')\n\nputs value.convert(price).round(2)\n```\n\nFetching price data, caching that data, and rounding the result are all\nresponsibilities of the caller.\n\n\n## Parsing strings\n\nUse the `Monies` method to convert strings that are expected to be valid and\ndon't contain special formatting, such as those in source code and databases:\n\n```ruby\nMonies('12345.6')\n```\n\nUse the `Monies.parse` method to parse strings that could be invalid or could\ncontain special formatting like thousand separators, currency codes, or symbols:\n\n```ruby\nMonies.parse('£1,999.99')\nMonies.parse('1.999,00 EUR')\n```\n\nAn `ArgumentError` exception is raised for invalid input:\n\n```ruby\nMonies.parse('notmoney')  # raises ArgumentError\n```\n\nCurrency symbols and currency codes are defined in `Monies.symbols` which can\nbe updated to support additional currencies using #[]= or #update. For example:\n\n```ruby\nMonies.symbols[\"\\u20BF\"] = 'BTC'\n\nMonies.symbols.update({\"\\u20BF\" =\u003e 'BTC'})\n\nMonies.parse('1,000 BTC')\n```\n\n\n## Formatting strings\n\nUse the `Monies.format` method to produce formatted strings:\n\n```ruby\nMonies.format(Monies('1234.56', 'USD'))  # \"1,234.56\"\n```\n\nSpecify the `code` or `symbol` options to include the currency code or symbol:\n\n```ruby\nMonies.format(Monies('1234.56', 'USD'), code: true)  # \"1,234.56 USD\"\n\nMonies.format(Monies('1234.56', 'USD'), symbol: true)  # \"$1,234.56\"\n```\n\nSpecify the name of the format to use different formatting rules:\n\n```ruby\nMonies.format(Monies('1234.56', 'USD'), :eu)  # \"1.234,56\"\n```\n\nThe default format is `:en` and can be changed by updating `Monies.formats`,\nfor example to change the default format to the built-in `:eu` format:\n\n```ruby\nMonies.formats[:default] = Monies.formats[:eu]\n```\n\nTo create a custom format first create a `Monies::Format` subclass,\nand then add the format to `Monies.formats`. For example:\n\n```ruby\nclass CustomFormat \u003c Monies::Format::EN\n  # ...\nend\n\nMonies.formats[:custom] = CustomFormat.new\n```\n\n\n## BigDecimal integration\n\nMonies integrates with the [bigdecimal gem](https://rubygems.org/gems/bigdecimal)\nfor multiplication and currency conversion. For example:\n\n```ruby\nrequire 'bigdecimal/util'\n\nMonies('1.23', 'USD') * BigDecimal('0.1')\n```\n\nUse the `Monies` method to convert from a `BigDecimal` value:\n\n```ruby\nMonies(BigDecimal(10), 'USD')\n```\n\nUse the #to_d method to convert to a `BigDecimal` value:\n\n```ruby\nmonies.to_d\n```\n\nSpecify a currency argument to use `BigDecimal` values for currency conversion:\n\n```ruby\nmonies = Monies('1.11', 'BTC')\nmonies.convert(BigDecimal(100_000), 'USD').round(2)\n```\n\n\n## Percentage integration\n\nMonies integrates with the [percentage gem](https://rubygems.org/gems/percentage)\nfor percentage calculations. For example:\n\n```ruby\nrequire 'percentage'\n\ncapital_gains = Monies(10_000, 'GBP')\n\ntax_rate = Percentage.new(20)\n\ntax_liability = capital_gains * tax_rate\n\nputs tax_liability\n```\n\n\n## Sequel integration\n\nMonies integrates with the [sequel gem](https://rubygems.org/gems/sequel)\nto support database serialization. For example:\n\n```ruby\nclass Product \u003c Sequel::Model\n  plugin Monies::Serialization::Sequel\n\n  serialize_monies :price\nend\n```\n\nThis will serialize the value and the currency as a single string.\n\nYou can also specify the currency at the model/application level using the\ncurrency keyword argument:\n\n```ruby\nserialize_monies :price, currency: Monies.currency\n```\n\nThis will serialize just the value as a single string.\n\nYou can also use two columns, one for the value and an additional string column\nto store the currency:\n\n```ruby\nserialize_monies :price, currency: :currency\n```\n\n## ActiveRecord integration\n\nMonies integrates with the [activerecord gem](https://rubygems.org/gems/activerecord)\nto support database serialization. For example:\n\n```ruby\nclass Product \u003c ApplicationRecord\n  include Monies::Serialization::ActiveRecord\n\n  serialize_monies :price\nend\n```\n\nUsage of `serialize_monies` is identical to the [sequel integration](#sequel-integration).\n\n\n## License\n\nMonies is released under the LGPL-3.0 license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freadysteady%2Fmonies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freadysteady%2Fmonies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freadysteady%2Fmonies/lists"}