Integers and Floats

Learn to Program, Third Edition — by Chris Pine (12 / 116)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Printing to the Screen | TOC | Simple Arithmetic 👉

In most programming languages (and Ruby is no exception), numbers without a decimal point are called integers, and numbers with a decimal point 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 use integers more often than they use floats. 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. Many programs even use integers for money, separately keeping track of the number of pennies.

Floats, on the other hand, are used more for academic purposes, like physics experiments and such, and for audio and video programs (including 3D applications).

Now let’s look at how to use simple arithmetic to solve problems that we might use a calculator for.

👈 Printing to the Screen | TOC | Simple Arithmetic 👉

Learn to Program, Third Edition by Chris Pine can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.