defmodule Temperature do
@moduledoc "Converts between Celsius and Fahrenheit."
@doc "Celsius to Fahrenheit."
@spec to_f(number()) :: float()
def to_f(c), do: c * 9 / 5 + 32
@spec to_c(number()) :: float()
def to_c(f), do: (f - 32) * 5 / 9
# Multi-line bodies use do/end.
def describe(c) do
"#{c}°C is #{format(to_f(c))}°F"
end
defp format(value), do: :erlang.float_to_binary(value, decimals: 1)
end
IO.puts(Temperature.describe(100))
IO.inspect(Temperature.to_c(212))
100°C is 212.0°F
100.0