Money as represented by SumUp's newer Readers API: an integer value in
minor units, an explicit minor_unit (decimal exponent), and an ISO 4217
currency code, e.g. %{"value" => 5033, "minor_unit" => 2, "currency" => "EUR"} for €50.33.
This is the numerically-safe representation (no floating point rounding)
and correctly handles zero-decimal currencies such as JPY, CLP, COP and
HUF, where minor_unit is 0 and value is already the full amount.
Summary
Functions
Builds a t/0 directly from a major-unit decimal amount, e.g.
Sumup.Money.MinorUnit.from_decimal(50.33, "EUR", 2) == %Sumup.Money.MinorUnit{value: 5033, minor_unit: 2, currency: "EUR"}.
Builds a t/0 from a decoded JSON map (value/minor_unit/currency).
Converts back to a major-unit decimal amount, e.g. 5033 cents at minor_unit: 2 becomes 50.33.
Encodes back into the wire shape expected by the Readers API.
Types
@type t() :: %Sumup.Money.MinorUnit{ currency: String.t(), minor_unit: non_neg_integer(), value: integer() }
Functions
@spec from_decimal(number(), String.t(), non_neg_integer()) :: t()
Builds a t/0 directly from a major-unit decimal amount, e.g.
Sumup.Money.MinorUnit.from_decimal(50.33, "EUR", 2) == %Sumup.Money.MinorUnit{value: 5033, minor_unit: 2, currency: "EUR"}.
Builds a t/0 from a decoded JSON map (value/minor_unit/currency).
Converts back to a major-unit decimal amount, e.g. 5033 cents at minor_unit: 2 becomes 50.33.
Encodes back into the wire shape expected by the Readers API.