January 2019
Intermediate to advanced
246 pages
5h 23m
English
Let’s apply all this to a running project. Our goal is to choose a base currency and then roughly convert amounts in other currencies to that base, like: 42 US Dollars (USD) = 277.86846192 Chinese Yuan (CNY). What are the types here? Currency codes such as “CNY” or “USD” are obviously Strings. So are their full names, like “Chinese Yuan”. To keep the code and the name together, we could use a Hash(String, String) like this:
| | CURRENCIES = { |
| | "EUR" => "Euro", |
| | "CAD" => "Canadian Dollar", |
| | "CNY" => "Chinese Yuan" |
| | } |
Store your base currency in a variable base. Conversion rates are decimal numbers. For this example, but not in bank production code, let’s use type Float64. So the data structure ...
Read now
Unlock full access