Decimal precision

Hi,

I have been playing a bit with the Rust implementation and I have realised the packet amount is defined in the protocol as an integer.

In the following example:

EUR -> XRP -> USD
with Rates (EUR/XRP 2.1)(XRP/USD 0.33)

A payment of EUR500 should deliver USD346.50.

But it is actually delivering 346 (u64 type in the Rust implementation).

I am sure I am missing something here?

Great question @elmurci!

The Interledger packet includes amounts as 64-bit unsigned integers that represent the minimum divisible units of an asset (cents for USD and EUR, drops for XRP, Wei for ETH, etc).

If we used the normal minimum divisible units, your example would have the amount in the ILP packet change from 50000 (EUR cents) to 105000000000 (XRP drops) to 34650 (USD cents). In practice, however, we’ve found it useful to use a different asset scale for Interledger packets than the normal settlement asset scale so we’ve sort of taken to using a scale of 9 for most assets.

We avoided using floating points from the beginning because they are notoriously problematic to use for representing amounts of money. We did have a decimal floating point format for a bit but gave that up because we realized that, since we send the amount without the currency code already, the currency scale can also be part of the context agreed upon between two peers. In Interledger.rs, the asset_code and asset_scale are both set as parameters on the Account.

makes total sense, I know I was missing something :slight_smile: