How does the REPL handle floats, and how can you perform Mathematical functions on them?

There is a lot to say about floating point arithmetics and all the ways it can go wrong, and all the tricks and techniques you can use to still make it produce “close enough” results.

I find the simplest way to convince yourself they should not be used when counting money is to just do 0.1 + 0.2 in your favourite language.

Here’s a line of Javascript I just executed in my browser console:

> 0.1 + 0.2 == 0.3
< false

Though, of course:

$ daml repl
> 0.1 + 0.2 == (0.3 : Decimal)
True
>
2 Likes