Elixir - Conversor Celsius - Farenheit (version 2)

mat130517
1,195 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Conversor Celsius - Farenheit

Programa conversor. Prueba para curso iniciación a Elixir página web.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
defmodule Funciones do
def convertir(tipo, grados) do
grados
|> formula(tipo) # es como si fuera formula(grados,:tipo)
|> redondear
|> cadenapantalla
|> IO.puts
end
defp formula(num,select) do
case select do
:aCel -> (num-32) * 5/9
:aFah -> (num * 9/5) +32
end
end
defp redondear(num), do: Float.round(num,2)
defp cadenapantalla(num) do
"El resultado es " <> Float.to_string(num) <> " Fahranheit"
end
end
Funciones.convertir(:aCel,40)
Funciones.convertir(:aFah,10)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Tech.io mola mucho, pero mucho mucho !

If you want a more complex example (external libraries, viewers...), use the Advanced Elixir template

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content