{"id":28353103,"url":"https://github.com/gmtprime/decimal_env","last_synced_at":"2025-07-07T12:02:44.771Z","repository":{"id":57488833,"uuid":"71350954","full_name":"gmtprime/decimal_env","owner":"gmtprime","description":"Provides macros to use Decimals with regular Elixir operators","archived":false,"fork":false,"pushed_at":"2021-10-21T13:06:47.000Z","size":24,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-28T00:11:33.233Z","etag":null,"topics":["decimal","elixir","macros"],"latest_commit_sha":null,"homepage":null,"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/gmtprime.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["alexdesousa"]}},"created_at":"2016-10-19T11:37:54.000Z","updated_at":"2024-03-28T06:28:59.000Z","dependencies_parsed_at":"2022-08-29T15:10:26.934Z","dependency_job_id":null,"html_url":"https://github.com/gmtprime/decimal_env","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/gmtprime/decimal_env","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmtprime%2Fdecimal_env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmtprime%2Fdecimal_env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmtprime%2Fdecimal_env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmtprime%2Fdecimal_env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gmtprime","download_url":"https://codeload.github.com/gmtprime/decimal_env/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmtprime%2Fdecimal_env/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260293269,"owners_count":22987589,"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":["decimal","elixir","macros"],"created_at":"2025-05-28T00:10:42.404Z","updated_at":"2025-06-17T04:32:39.026Z","avatar_url":"https://github.com/gmtprime.png","language":"Elixir","funding_links":["https://github.com/sponsors/alexdesousa"],"categories":[],"sub_categories":[],"readme":"# DecimalEnv\n\n![Build status](https://github.com/gmtprime/decimal_env/actions/workflows/checks.yml/badge.svg) [![Hex pm](http://img.shields.io/hexpm/v/decimal_env.svg?style=flat)](https://hex.pm/packages/decimal_env) [![hex.pm downloads](https://img.shields.io/hexpm/dt/decimal_env.svg?style=flat)](https://hex.pm/packages/decimal_env)\n\n\u003e **Environment** (_noun_): The totality of the natural world, often excluding\n\u003e humans.\n\nThis library provides a macro to encapsulate `Decimal` operations while using\nElixir operators e.g:\n\n```elixir\niex(1)\u003e import DecimalEnv\niex(2)\u003e decimal do\n...(2)\u003e   21.0 + \"21.0\"\n...(2)\u003e end\n#Decimal\u003c42.0\u003e\n```\n\n\u003e For more information on `Decimal` library, you can go to\n\u003e [its documentation](https://hexdocs.pm/decimal/readme.html).\n\nThere are two options we can provide to control the operations happening inside\nthe `decimal` block:\n\n- `:context` - `Decimal.Context` struct. it can also be a `keyword` list. Check\n  [its documentation](https://hexdocs.pm/decimal/Decimal.Context.html#content)\n  for more information.\n- `:as` - In which type we should have the result. The possible values are\n  the following:\n  + `:decimal` (default)\n  + `:float`\n  + `:integer`\n  + `:string`\n  + `:xsd`\n  + `:raw`\n  + `:scientific`\n\nThe following would be a more complex example for the macro:\n\n```elixir\niex(1)\u003e import DecimalEnv\niex(2)\u003e decimal context: [precision: 2, rounding: :ceiling], as: :integer do\n...(2)\u003e   21.1 + 20\n...(2)\u003e end\n42\n```\n\nThe macro overloads all Elixir numeric operators and that's why the block can\ncontain any valid Elixir code e.g. the following snippet calculates the mean\nof the numbers `1`, `2`, `3` and `4` which is `2.5`:\n\n```elixir\niex(1)\u003e import DecimalEnv\niex(2)\u003e decimal as: :float do\n...(2)\u003e   values = [1,2,3,4]\n...(2)\u003e   amount = length(values)\n...(2)\u003e\n...(2)\u003e   Enum.reduce(values, 0, \u0026(\u00261 + \u00262)) / amount\n...(2)\u003e end\n2.5\n```\n\n## Installation\n\nAdd it to your `mix.exs`\n\n```elixir\ndef deps do\n  [{:decimal_env, \"~\u003e 1.0\"}]\nend\n```\n\n## Author\n\nAlexander de Sousa.\n\n## License\n\n`DecimalEnv` is released under the MIT License. See the LICENSE file for\nfurther details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmtprime%2Fdecimal_env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgmtprime%2Fdecimal_env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmtprime%2Fdecimal_env/lists"}