This module provides macros to encapsulate Decimal operations while using
Elixir arithmetic and comparison operators and functions.
Summary
Types
@type context() :: nil | keyword() | Decimal.Context.t()
Context.
Option.
@type options() :: [option()]
Options.
Output type.
@type type_name() ::
nil | :decimal | :float | :integer | :string | :scientific | :xsd | :raw
Type name.
Functions
Runs a block under the Decimal environment. All numeric values will be
converted to Decimal.
Options:
:context-Decimal.Contextstruct. it can also be akeywordlist.:as- In which type we should have the result. The possible values are the following::decimal(default):float:integer:string:xsd:raw:scientific
Examples
iex> import DecimalEnv
iex> decimal do: 42.42
Decimal.new("42.42")
iex> decimal do: 84.0 - 21 - "21"
Decimal.new("42.0")
iex> decimal as: :scientific do
...> "0.0000000002" + 0.000000004
...> end
"4.2E-9"
iex> decimal context: [precision: 2, rounding: :ceiling], as: :integer do
...> 21.1 + 20
...> end
42