{"id":13509355,"url":"https://github.com/theocodes/monetized","last_synced_at":"2026-02-21T15:05:05.647Z","repository":{"id":57529213,"uuid":"48300503","full_name":"theocodes/monetized","owner":"theocodes","description":"A lightweight solution for handling and storing money.","archived":false,"fork":false,"pushed_at":"2022-01-04T16:36:18.000Z","size":128,"stargazers_count":46,"open_issues_count":2,"forks_count":19,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T13:35:27.522Z","etag":null,"topics":["currencies","ecto","money"],"latest_commit_sha":null,"homepage":"http://hexdocs.pm/monetized","language":"Elixir","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/theocodes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-19T23:18:23.000Z","updated_at":"2024-12-10T09:54:41.000Z","dependencies_parsed_at":"2022-09-19T11:41:14.094Z","dependency_job_id":null,"html_url":"https://github.com/theocodes/monetized","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/theocodes/monetized","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theocodes%2Fmonetized","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theocodes%2Fmonetized/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theocodes%2Fmonetized/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theocodes%2Fmonetized/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theocodes","download_url":"https://codeload.github.com/theocodes/monetized/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theocodes%2Fmonetized/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29684076,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T14:31:22.911Z","status":"ssl_error","status_checked_at":"2026-02-21T14:31:22.570Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["currencies","ecto","money"],"created_at":"2024-08-01T02:01:06.561Z","updated_at":"2026-02-21T15:05:05.628Z","avatar_url":"https://github.com/theocodes.png","language":"Elixir","funding_links":[],"categories":["Text and Numbers"],"sub_categories":[],"readme":"# Monetized [Unmaintained]\n[![Build Status](https://travis-ci.org/theocodes/monetized.svg?branch=master)](https://travis-ci.org/theocodes/monetized)\n[![Deps Status](https://beta.hexfaktor.org/badge/all/github/theocodes/monetized.svg)](https://beta.hexfaktor.org/github/theocodes/monetized)\n[![Inline docs](http://inch-ci.org/github/theocodes/monetized.svg)](http://inch-ci.org/github/theocodes/monetized)\n\nAs a general rule, using floats to store money is a [bad idea](http://spin.atomicobject.com/2014/08/14/currency-rounding-errors/).\n\nEnter Monetized. A library that aims to facilitate the handling of money through a safe way to store currency values and\nand providing abstractions to perform arithmetical operations on those values.\n\nMonetized leverages [Decimal](https://github.com/ericmj/decimal)'s ability to safely handle arbitrary precision to perform calculations\non money values.\n\nA typical `%Monetized.Money{}` struct will contain a value in the shape of a `Decimal` struct and a currency (if any) as a string.\n\nRequires elixir version 1.3.x or above as per ecto 2.x\n\n## Usage\n\nMonetized also ships with a `Ecto.Type` that gives us an easier way to store money.\n\n```elixir\n\nalias Monetized.Money\n\nschema \"transaction\" do\n  field :description, :string\n  field :balance, Money, default: Money.zero\n\n  timestamps\nend\n\n```\n\nBy doing this we're able to pass a `%Money{}` struct to the changeset and\ninsert in the `Repo` since Ecto knows how to convert that struct into a primitive\ntype to save and back when you read from it.\n\n```elixir\n\nbalance = Money.make(\"£ 100.50\")\nchangeset = Transaction.changeset(%Transaction{}, %{description: \"Invoice payment\", balance: balance})\n\n# Or\n\nbalance = %{value: \"100.50\", currency: \"GBP\"}\nchangeset = Transaction.changeset(%Transaction{}, %{description: \"Invoice payment\", balance: balance})\n\n```\n\nCheck the [docs](http://hexdocs.pm/monetized/api-reference.html) for more.\n\n## Other usage\n\n```elixir\nalias Monetized.Money\nalias Monetized.Math\n\n# Create with a string\niex\u003e item_one = Money.make(\"£ 200.50\")\n#Money\u003c200.50GBP\u003e\n\n# Or a float\niex\u003e item_two = Money.make(10.25, [currency: \"GBP\"])\n#Money\u003c10.25GBP\u003e\n\n# Adding two moneys together\niex\u003e Math.add(item_one, item_two)\n#Money\u003c210.75GBP\u003e\n\n# Or an integer\niex\u003e balance = Money.make(100_000, [currency: \"USD\"])\n#Money\u003c100000.00USD\u003e\n\n# Substracting from money (currency inferred from balance)\niex\u003e result = Math.sub(balance, 50_000)\n#Money\u003c50000.00USD\u003e\n\n# Getting the string representation\niex\u003e Money.to_string(result, [currency_symbol: true])\n\"$ 50,000.00\"\n\n# You can also use `from_integer/2`, `from_float/2`, `from_decimal/2` and `from_string/2`\n# respectively if the desired behavior is to raise when the amount is \n# not of the expected type.\n\n# If either the symbol or the currency key is found within the string,\n# that currency will be used. However, if a different currency is given in the\n# options, it will take precedence.\n\niex\u003e Money.from_string(\"£ 200\")\n#Money\u003c200.00GBP\u003e\n\niex\u003e Money.from_string(\"200 EUR\")\n#Money\u003c200.00EUR\u003e\n\niex\u003e Money.from_integer(200)\n#Money\u003c200.00\u003e\n\niex\u003e Money.from_float(200.50)\n#Money\u003c200.50\u003e\n\niex\u003e decimal = Decimal.new(10.25)\n...\u003e Money.from_decimal(decimal, currency: \"EUR\")\n#Money\u003c10.15EUR\u003e\n\niex\u003e Money.from_integer(\"10\")\n** (FunctionClauseError) no function clause matching in Monetized.Money.from_integer/2\n    (monetized) lib/money.ex:204: Monetized.Money.from_integer(\"10\", [])\n\n```\n\nCheck the [docs](http://hexdocs.pm/monetized/api-reference.html) for more examples\n\n## Config\n\n\n```elixir\nconfig :monetized, config: [\n  delimiter: \",\",\n  separator: \".\",\n  currency: \"USD\",\n  format: \"%cs %n%s%d\"\n]\n```\n\n## Installation\n\n  Add monetized to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:monetized, \"~\u003e 0.5.0\"}]\nend\n\n```\n\n## TODO\n\n- [ ] New currencies can be added through the package's config\n- [ ] 1.0.0 ! yay!\n\n## Benchmarking\n\n```sh-session\n$ mix deps.get\n$ MIX_ENV=bench mix compile\n$ MIX_ENV=bench mix bench\n```\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for details.\n\n## Licensing\n\nSee [LICENSE.md](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheocodes%2Fmonetized","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheocodes%2Fmonetized","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheocodes%2Fmonetized/lists"}