Dinesh
Dinesh

Reputation: 2204

print boolean in Erlang

I am new to Erlang. I wanted to know how to print boolean in Erlang. I have a function which checks if a number is even or not. It returns a boolean value.

io:format("The number is even number?  ~d~n", [is_even(X)] ).

the output is 1 or 0 now. How can I display "true" or "false"?

Upvotes: 1

Views: 1303

Answers (1)

tkowal
tkowal

Reputation: 9289

In Erlang true and false are atoms. ~d says "interpret it as integer". I suggest using ~p instead. This prints most of the things as you would expect and even does pretty printing! You only have to be careful with printing lists of numbers, where all of the numbers are between 32 and 255, because they will be interpreted as strings - use ~w for them.

Upvotes: 3

Related Questions