Intern Track Roadmap

Ruby data: numbers & booleans

This course covers how Ruby handles numbers and booleans. It starts with the difference between Integer and Float, how the two mix in arithmetic, and how to convert between them. It then explains integer division and the % operator, why 0.1 + 0.2 gives 0.30000000000000004, and how to store money as integer cents or BigDecimal. Later lessons cover numeric methods such as round, abs and even?, the values true and false, and Ruby's truthiness rule. A final challenge combines these ideas in an average method.

What you'll learn

  • ✓Telling Integer from Float and converting with to_f and to_i
  • ✓How integer division and the % operator behave
  • ✓Why floats are imprecise and how to compare or store them safely
  • ✓Using round, ceil, floor, abs, even?, odd? and zero?
  • ✓Booleans as objects produced by comparison operators
  • ✓Ruby's truthiness rule, where only false and nil are falsy
Free preview · Lesson 1 3 min read

Integer and float: two kinds of number

5 and 5.0 are the same value in math. In Ruby they're different kinds of object.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...