Integer and Float

In most programming languages (and Ruby is no exception), numbers without decimal points are called integers, and numbers with decimal points are usually called floating-point numbers or, more simply, floats.

Here are some integers:

5
-205
9999999999999999999999999
0

And here are some floats:

54.321
0.001
-205.3884
0.0

In practice, most programs don’t use floats; they use only integers. (After all, no one wants to look at 7.4 emails, browse 1.8 web pages, or listen to 5.24 of their favorite songs.) Floats are used more for academic purposes (physics experiments and such) and for audio and video (including 3D) programs. Even most money programs use integers; they just keep track of the number of pennies!

Get Learn to Program, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.