Want to learn?

Integers and Floats

Integer representation

Documentation

There are four integer representations you can use:

  • Decimal

    iex> 1000
    1000
    
  • Hexadecimal

    iex> 0x1F
    31
    
  • Octal

    iex> 0o777
    511
    
  • Binary

    iex> 0b1010
    10
    

When you're dealing with a big decimal number, you might want to separate its digits into groups with an underscore. For example: 1000000 equals 1_000_000.

Another cool fact about big numbers is that there is no limit on the size of integers.

Float representation

Documentation

Floating-point numbers have 16 digits of accuracy with the maximum value of 1038. The only requirement for Float data representation is at least one digit before and after the decimal point.

iex> 10.000e1
100.0
iex> 10.5
10.5
iex> 0.82812
0.82812

Arithmetical operators

Elixir supports basic arithmetical operations:

  • +

    iex> 5 + 5
    10
    
  • -

    iex> 5 - 5
    0
    
  • / - result of this operator is represented by Float type

    iex> 10 / 10
    1.0
    
  • div - result of this operator is represented by Integer type

    iex> div(10, 10)
    1
    
  • *

    iex> 5 * 5
    25
    
  • rem - remainder operator, result will have the same sign as the function’s first argument, which is the only difference comparing to modulo

    iex> rem(14, 5)
    4
    iex> rem(-14, 5)
    -4
    

Comparison operators

Documentation

In most cases you will use comparison operators for numbers, however it's not a must. In Elixir, comparison is based on type according to rule:

number < atom < reference < function < port < pid < tuple < map < list < binary

List of comparison operators:

  • value equality

    iex> 1 == 1
    true
    iex> 1 == 1.0
    true
    
  • strict equality - checks value and type equality

    iex> 1 === 1
    true
    iex> 1 === 1.0
    false
    
  • value inequality

    iex> 1 != 2
    true
    
  • strict inequality

    iex> 1 !== 1
    false
    iex> 1 !== 1.0
    true
    
  • greater than

    iex> 2 > 1
    true
    
  • greater than or equal to

    iex> 2 >= 1
    true
    iex> 2 >= 2
    true
    iex> 2 >= 2.5
    false
    
  • lower than

    iex> 1 < 2
    true
    
  • lower than or equal to

    iex> 1 <= 2
    true
    iex> 1 <= 1
    true
    iex> 1 <= 0.5
    false
    
Check our latest product - it's based on our experience of managing over 50-people strong company. The tool we're missing as a small company and not an enterprise.

humadroid.io is an employee and performance management software. It's an unique tool allowing everyone to be in the loop - by having up to date info about co-workers, time-off, benefits, assets, helping with one-on-ones, being a go-to place for company-wide announcements.

Check out humadroid.io
Top

Contact us

* Required fields

The controller of your personal data provided via this contact form is Prograils sp. z o.o., with a registered seat at Sczanieckiej 9A/10, 60-215 Poznań. Your personal data will be processed in order to respond to your inquiries and for our marketing purposes (e.g. when you ask us for our post-development, maintenance or ad hoc engagements for your app). You have the rights to: access your personal data, rectify or erase your personal data, restrict the processing of your personal data, data portability and to object to the processing of your personal data. Learn more.

Notice

We do not track you online. We use only session cookies and anonymous identifiers for the purposes specified in the cookie policy. No third-party trackers.

I understand
Elo Mordo!Elo Mordo!