Calling Erlang function for Elixir, how do I skip the :ok atom?

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])

2 Likes

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.

3 Likes

Aha, this makes more sense now. Thanks!