For each one of the types, there is a function:
- http://elixir-lang.org/docs/stable/Kernel.html#integer_to_binary/1
- http://elixir-lang.org/docs/stable/Kernel.html#float_to_binary/1
If you want a general number_to_binary
function, try simply using inspect
(that is Kernel.inspect
, not IO.inspect
).
a = 3
b = 3.14
inspect a
% => "3"
inspect b