View Source QRNBU.Types.Amount (NBU payment QR v0.3.3)
Monetary amount with validation for NBU QR codes.
Constraints
- Minimum: 0.01 UAH
- Maximum: 999,999,999.99 UAH
- Precision: Exactly 2 decimal places
- Must be positive (non-zero)
Examples
iex> QRNBU.Types.Amount.new(100.50)
{:ok, %QRNBU.Types.Amount{}}
iex> QRNBU.Types.Amount.new(Decimal.new("50.00"))
{:ok, %QRNBU.Types.Amount{}}
iex> QRNBU.Types.Amount.new(10050) # Integer in kopiykas
{:ok, %QRNBU.Types.Amount{}} # Converts to 100.50
iex> QRNBU.Types.Amount.new(0)
{:error, "Amount must be at least 0.01"}
iex> QRNBU.Types.Amount.new(-50)
{:error, "Amount must be positive"}
Summary
Functions
Creates a new Amount with validation.
Extracts the Decimal value from an Amount.
Converts Amount to string with exactly 2 decimal places.
Types
@opaque t()
Functions
Creates a new Amount with validation.
Accepts:
Decimal.t()- Direct decimal valuefloat()- Converted to Decimalinteger()- Treated as kopiykas (cents), divided by 100String.t()- Parsed as decimal string
Returns {:ok, amount} if valid, {:error, reason} otherwise.
Extracts the Decimal value from an Amount.
Converts Amount to string with exactly 2 decimal places.