The Float data type
The data type of floating point numbers is Float
. By default, Float
matches floating point numbers
within the limitations of Ruby's Float class. Practically
speaking, this means a 64-bit double precision floating point value. You can use parameters to
restrict which values Float
matches.
Parameters
The full signature for Float
is:
Float[<MIN VALUE>, <MAX VALUE>]These parameters are optional. They must be listed in order; if you need to specify a later parameter, you must also specify values for any prior ones.
Position | Parameter | Data type | Default | Description |
---|---|---|---|---|
1 | Minimum value | Float | negative infinity | The minimum value for the float. This parameter accepts the special
value default , which uses its
default value. |
2 | Maximum value | Float | infinity | The maximum value for the float. This parameter accepts the special
value default , which uses its
default value. |
Examples:
Float
Matches any floating point number.
Float[1.6]
Matches any floating point number greater than or equal to 1.6.
Float[1.6, 3.501]
Matches any floating point number from 1.6 to 3.501, inclusive.
For more information about Float see Ruby's Float class docs.