Skip to main content

Rounding

There is no support for floating or decimal numbers on the Formance stack and Numscript will always make sure non integer values resulting from monetary computations are balanced.

In practical, this means appropriately distributing the non integer allocation remainder to accounts. Numscript works by flooring any computed amount and subsequently spreading the remaining amount as fairly as possible starting from top to bottom.

In the example below:

The @rider account will receive COIN 50 and the @taxes account COIN 49. The opposite can be achieved by reversing the order of destinations:

In a more complex example below, we are splitting 99 into 5 which would result in 19.8 allocated to each account. Numscript will first allocate 19 to every account, then attempt to distribute the remaining 4 evenly starting from @a

Which will resolve into the following postings:

[
{
source: "world",
destination: "a",
amount: 20,
asset: "COIN"
},
{
source: "world",
destination: "b",
amount: 20,
asset: "COIN"
},
{
source: "world",
destination: "c",
amount: 20,
asset: "COIN"
},
{
source: "world",
destination: "d",
amount: 20,
asset: "COIN"
},
{
source: "world",
destination: "e",
amount: 19,
asset: "COIN"
}
]