Do Daml `Numeric` and `Decimal` data types use a base-10 or base-2 representation?

This is partly inspired by another question.

The accepted answer mentioned all rational numbers in Daml are fixed point numbers because that would avoid the problem of floating point arithmetic (i.e. 0.1 + 0.2 /= 0.3 in most languages that employ floating point numbers.

However, I do not believe that line of reasoning is correct because C#, a language I am quite familiar with, only has floating point numbers and it uses two different data types to avoid the 0.1 + 0.2 /= 0.3 problem. It has double (a base-2 floating point number type, which has the issue) and decimal (a base-10 floating point number type, which aligns with how most humans do daily/financial calculations, and is recommended for monetary calculations).

I understand at the bare metal, computer hardware level, everything eventually has to be in binary floating point, regardless of the programming language used. But if my understanding is correct, floating or fixed point numbers should not be the reason why we have the 0.1 + 0.2 /= 0.3 issue. This should be determined by the base of the floating/fixed point number used, right?

That leads to my question, do fixed point numbers in Daml use a base-10 or a base-2 representation?

1 Like

Daml Numeric’s are decimals so base 10. They are somewhat similar to Decimal in F# but they have a fixed scale and precision.

1 Like