class Float

A Float object stores a real number using the native architecture’s double-precision floating-point representation.

Float Imprecisions

Some real numbers can be represented precisely as Float objects:

37.5    # => 37.5
98.75   # => 98.75
12.3125 # => 12.3125

Others cannot; among these are the transcendental numbers, including:

Some floating-point computations in Ruby give precise results:

1.0/2   # => 0.5
100.0/8 # => 12.5

Others do not:

See:

Note that precise storage and computation of rational numbers is possible using Rational objects.

Creating a Float

You can create a Float object explicitly with:

You can convert certain objects to Floats with:

What’s Here

First, what’s elsewhere. Class Float:

Here, class Float provides methods for:

Querying

Comparing

Converting