There is no support for floating point or decimal numbers in Numscript, which will always make sure non integer values resulting from monetary computations are balanced. Practically, 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:Documentation Index
Fetch the complete documentation index at: https://docs.formance.com/llms.txt
Use this file to discover all available pages before exploring further.
@rider account will receive COIN 50 and the @taxes account COIN 49. The opposite can be achieved by reversing the order of destinations:
@a:
Fixed fees and allocation order
When combining fixed amounts with percentage-based allocations, the order of destinations matters due to the multi-pass resolution mechanism.The problem
Consider a transaction splitting funds between a payment provider (fixed fee + percentage), a franchise fee (percentage), and a store (remaining):@payment_provider to receive exactly 7 cents as a fixed fee, but it actually receives 8 cents. This happens because of the two-pass allocation mechanism.
How multi-pass allocation works
First pass - Numscript allocates whole amounts:7/1999 * 1999 = 7→@payment_provider0.6% * 1999 = 11.994→ floors to11for@payment_provider(keeps 0.994 aside)0.5% * 1999 = 9.995→ floors to9for@franchise_fee(keeps 0.995 aside)remaining = 1999 - 7 - 11 - 9 - ceil(0.994 + 0.995) = 1970→@store
- Total distributed:
1999 - 2 = 1997 - Remaining to distribute:
2 cents - Distribution is top to bottom: first position (
@payment_provider) gets +1, second position (@payment_provideragain) gets +1
@payment_provider receives 7 + 1 = 8 cents instead of the expected 7.