As we have seen in the Data Types topic, there are five types of Numbers supported by Ruby.
Let us see them below :
x = 5 y = -3 puts x.class puts y.class
x = 5
y = -3
puts x.class puts y.class
Fixnum
x = 98765432109876543210 puts x.class
x = 5
puts x.class
Bignum
x = 5.987 puts x.class
x = 0.1 y = 0.2 z = x + y puts z
require 'bigdecimal' x = BigDecimal("0.1") y = BigDecimal("0.2") z = x + y if (z == 0.3) puts "The result matches 0.3" end
require bigdecimal
x = BigDecimal("0.1") y = BigDecimal("0.2")
z = x + y
if (z == 0.3) puts "The result matches 0.3" end
The result matches 0.3
x = 4/2r puts x.class
x = 4/2r
puts x.class