Hello,
I’m learning Elixir and I’m trying to call:
:io.format("~.2f", [3.14567890])
Which gets me 3.15ok.
How do I get rid of the ok part?
Hello,
I’m learning Elixir and I’m trying to call:
:io.format("~.2f", [3.14567890])
Which gets me 3.15ok.
How do I get rid of the ok part?
Use :io_lib
instead of :io
:
to_string :io_lib.format("~.2f", [3.14567890])
Thank you! Are there any significant differences between :io and :io_lib ?
Well :io_lib.format/2
does format into a string and returns it, while :io:format/2
prints a formatted string and returns :ok
.
Therefore, if you want to print just use :io
, the end user will never see the :ok
part in his terminal unless you are using it totally wrong.
Aha, this makes more sense now. Thanks!