Numbers
suggest changeRemarks
Numbers hierarchy
Ruby includes several built-in classes to represent numbers:
Numeric
Integer
Float # 1.0
Complex # (1+0i)
Rational # Rational(2, 3) == 2/3
BigDecimal # not loaded by default
The most common are:
Integerto represent positive and negative whole numbers of any sizeFloatto represent floating point numbers
BigDecimal is the only one not loaded by default. You can load it with:
require "bigdecimal"
Ruby uses the Integer class for whole numbers of every size. The old Fixnum and Bignum constants were removed in Ruby 2.4.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents