`:erlang.float` vs `value * 1.0`: Which is the prefered way?

So my question is quite simple and i have found no conclusive answer on forum, google or AI.

Should we use :erlang.float for Integer to Float conversion or division / multiplications? It seems that :erlang.float is not really used as its not typed(?) and the convention is, to use the Elixir mappings for Erlang stuff.

Claude gave me value / 1 which at first, seemed weird. Since there is no Integer.to_float i would like to hear your opinions on which you prefer and why.

I’d start by asking what reason you have to convert an integer to a float. Then I’d look at how performant this needs to be (hot path or not) and then I’d wonder if it’s worth comparing performance between a bif/nif float/1 vs doing a random calculation like x/1 or x*1.0. I’d guess all of them are fast, but no matter what, one will be the fastest. From a readability standpoint float/1 will convey the cleanest that all you do there is convert integer to float.

Thanks for your answer. For instance, we have a Ash calculation which defines type: :float and we get values as float as strings and integers. Therefore we need to convert int to float. Im not really worried about performance as this is not hot path but more what the community uses so our code is in line with best practices.

Hi, if you plan to do arithmetic with this float better option is to use Decimal, as Decimal handles precision for those operations.

Decimal.new(42)