# Decimal.Context

The context is kept in the process dictionary. It can be accessed with `Decimal.get_context/0` and `Decimal.set_context/1`.

The default context has a precision of 9, the rounding algorithm is `:half_up`. The set trap enablers are `:invalid_operation` and `:division_by_zero`.

## Fields

• `precision` - Maximum number of decimal digits in the coefficient. If an operation’s result has more digits it will be rounded to `precision` digits with the rounding algorithm in `rounding`.
• `rounding` - The rounding algorithm used when the coefficient’s number of exceeds `precision`. Strategies explained below.
• `flags` - A list of signals that for which the flag is sent. When an exceptional condition is signalled it’s flag is set. The flags are sticky and will be set until explicitly cleared.
• `traps` - A list of set trap enablers for signals. When a signal’s trap enabler is set the condition causes `Decimal.Error` to be raised.

## Rounding algorithms

• `:down` - Round toward zero (truncate). Discarded digits are ignored, result is unchanged.
• `:half_up` - If the discarded digits is greater than or equal to half of the value of a one in the next left position then the coefficient will be incremented by one (rounded up). Otherwise, the discarded digits will be ignored.
• `:half_even` - Also known as “round to nearest” or “banker’s rounding”. If the discarded digits is greater than half of the value of a one in the next left position then the coefficient will be incremented by one (rounded up). If they represent less than half discarded digits will be ignored. Otherwise (exactly half), the coefficient is not altered if it’s even, or incremented by one (rounded up) if it’s odd (to make an even number).
• `:ceiling` - Round toward +Infinity. If all of the discarded digits are zero or the sign is negative the result is unchanged. Otherwise, the coefficient will be incremented by one (rounded up).
• `:floor` - Round toward -Infinity. If all of the discarded digits are zero or the sign is positive the result is unchanged. Otherwise, the sign is negative and coefficient will be incremented by one.
• `:half_down` - If the discarded digits is greater than half of the value of a one in the next left position then the coefficient will be incremented by one (rounded up). Otherwise the discarded digits are ignored.
• `:up` - Round away from zero. If all discarded digits are zero the coefficient is not changed, otherwise it is incremented by one (rounded up).
Source

## Types ↑

t :: %Decimal.Context{precision: pos_integer, rounding: Decimal.rounding, flags: [Decimal.signal], traps: [Decimal.signal]}