- Mastering Elixir
- André Albuquerque Daniel Caixinha
- 111字
- 2021-08-05 10:42:44
Integers
This type contains, as you would expect, numbers that can be written without a fractional component. The size of integers adjusts dynamically according to its magnitude—you don't have to worry about this: an integer will simply occupy more words in memory as it grows. Here's some basic arithmetic with integers:
iex> 25 + 8
33
To improve the readability of the code, you can also use underscores in between the digits of an integer, as shown here:
iex> 1_000_000 - 500_000
500000
Besides decimal, Elixir also supports integers written in binary, octal, and hexadecimal (using 0b, 0o, and 0x, respectively):
iex> 0b10001
17
iex> 0o21
17
iex> 0x11
17