scale for precision. Managing precision and scaling is critical for handling transactions and balances accurately.
Each transaction is recorded with two key attributes:
amount: Represents the value of the transaction as an integer.scale: Specifies the number of decimal places associated with the amount.
Understanding amount
The amount is the value to be debited and credited from the origin or to the destination accounts. It can be specified in three ways:- amount: This is the direct definition of the value according to the scale. For example, an amount of 10 (
:amount BRL 100|2). - share: This indicates a percentage of the total amount that will be distributed to a given account. For instance, if you want to send 90% of the amount, it should be formatted as
:share 90, meaning 90%. - remaining: This indicates that the remaining total amount will be sent to an account.
Understanding scale
Thescale is a parameter designed to define how the transaction amount is interpreted.
ImportantThis parameter is supported only in Midaz v2.x.x and earlier.
scale can be set to a positive integer to specify the number of decimal places for interpreting the transaction value. For example, if scale is set to 2, a value of 1000 will be interpreted as 10.00.
In the following table, you can find a few examples of how the scale works.
| Asset | Amount | Scale | Interpretation |
|---|---|---|---|
| BRL | 576 | 2 | 5.76 |
| ETH | 38 | 5 | 0.00038 |
| BTC | 14 | 6 | 0.000014 |
| JPY | 154 | 0 | 154 |
Balance calculation
The balances are dynamically adjusted based on the biggest scale encountered among all recorded transactions. This ensures consistency while preserving precision. Example Workflow:- Transaction 1: BRL 0.1 using
amount = 1000andscale = 4. - Transaction 2: BRL 0.02 using
amount = 2000andscale = 5. - Transaction 3: BRL 10 using
amount = 10andscale = 0. - Transaction 4: BRL 10 using
amount = 100andscale = 1. - Transaction 5: BRL 0.03 using
amount = 30andscale = 3.
- After Transaction 1, the balance is stored with
scale = 4. - After Transaction 2, the balance adjusts to
scale = 5. - After Transaction 3, the balance remains at
scale = 5as no biggest scale is encountered.

