O'Reilly logo

Sams Teach Yourself Ruby in 21 Days by Mark Slagell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Numbers in Ruby

Let's start with numbers, which fall into two general categories: those that can have a fractional part (floats) and those that cannot (integers).

Integer Literals

A literal is just a way of expressing something directly in a language, as opposed to using a variable. Writing integer literals is intuitively pretty simple—we've been doing it all along—but Ruby offers some enhancements that help you express yourself readably.

A literal like 863527117 isn't very readable, because you have to look closely and count digits to know its magnitude. Is that in the hundreds of millions, or is it in the billions? When you aren't programming a computer, the convention is to break large numbers up with commas. Saying “863,527,117” makes it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required