Zoonk icon

There are a few types of numbers available in Ruby. Let's see some examples:

fruits = 10
lottery_prize = 42000000
price = 4.20
expression = 1 + 2i
fraction = Rational(1, 3)
precise_price = BigDecimal(4.20) 

You can also use underscore to separate places. For example, is the same as .

When you're performing calculations involving an and a , it will return a float number:

> 1 + 1.42 => 2.42 

Remember that when using divisions. If you try to divide two regular numbers, the result will be rounded:

> 3 / 2 => 1 

However, if you're using floats, then you'll get the correct result:

> 3/2.0 => 1.5 

But you can also round up or down floats by using the and methods, respectively:

> 1.5.ceil => 2 > 1.5.floor => 1 

Have a look at the docs for all methods you can use with floats, integers, complex numbers, rational numbers, and big decimal numbers.