DecimalEnv (DecimalEnv v1.0.0) View Source
This module provides macros to encapsulate Decimal operations while using
Elixir arithmetic and comparison operators and functions.
Link to this section Summary
Link to this section Types
Specs
context() :: nil | keyword() | Decimal.Context.t()
Context.
Specs
Option.
Specs
options() :: [option()]
Options.
Specs
Output type.
Specs
type_name() :: nil | :decimal | :float | :integer | :string | :scientific | :xsd | :raw
Type name.
Link to this section Functions
Specs
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<42.42>
iex> decimal do: 84.0 - 21 - "21"
#Decimal<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