# Amount

When moving an amount on a particular asset, it is important to keep in mind that Midaz follows a transaction-by-transaction scale definition.

For transactions that use a template, this can be abstracted.

For example, for a supermarket purchase in BRL, it is appropriate to use base 2 (10^2 = 100) with a minimum value of BRL 0.01. On the other hand, gas stations typically use base 4 (10^4 = 10000) with a minimum value of BRL 0.0001.

To correctly send the value, it is necessary to follow a specific method (`ASSET AMOUNT|SCALE`

). Here is an example:

To inform the amounts that will be debited and credited to the origin and destination, you have three options:

**Gross value**: This is the direct definition of a value according to the scale. For example, you can input 10 as the gross value.**Percentage value**: a percentage of the balance available (`balance.available`

) is sent. For example, 27.5% is sent for paying taxes. The percentage value will always be represented as, for example,`:share 90`

for 90%. If it is a percentage of a percentage, use for example "`:share 90 of 25`

" for 90% of 25% (or 22.5%).**Remaining amount**: This option involves sending part of the amount to account A and the rest to account B (for debits and credits).

**Saving and Returning the Value of Each Transaction**

**Saving and Returning the Value of Each Transaction**

To avoid rounding errors, we save the value of each transaction in the database using the scale at which they were made. When returning the balance, we use the smallest possible scale.

**Examples**

**Transaction 1 - [BRL 4 1000] (BRL 0.1):**Saved with a scale of 4 and an amount of 1000.**Transaction 2 - [BRL 5 2000] (BRL 0.02):**Saved with a scale of 5 and an amount of 2000.**Transaction 3 - [BRL 0 10] (BRL 10):**Saved with a scale of 0 and an amount of 10.**Transaction 4 - [BRL 1 100] (BRL 10):**Saved with a scale of 1 and an amount of 100.**Transaction 5 - [BRL 3 30] (BRL 0.03):**Saved with a scale of 3 and an amount of 30.

**Balance Calculation**

**Balance Calculation**

Transactions in the `transactions`

(and `operations`

) table are saved as described above. For the balance in the `accounts`

table, we always use the smallest possible scale.

**After Transaction 1**: The smallest scale is 4, so we return the total balance using scale 4.**After Transaction 2**: The smallest scale is now 5, so we return the balance using scale 5, considering transactions 1 and 2.**After Transaction 3**: Despite this transaction having a scale of 0, we continue using scale 5 for the balance as it remains the smallest scale used so far.

This method ensures accuracy and consistency in saving and returning transaction values and balances.

Last updated