class Float

Ruby on Rails 7.2.3

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Active Model Float Type

Attribute type for floating point numeric values. It is registered under the :float key.

class BagOfCoffee
  include ActiveModel::Attributes

  attribute :weight, :float
end

bag = BagOfCoffee.new

bag.weight = "0.25"
bag.weight # => 0.25

bag.weight = ""
bag.weight # => nil

bag.weight = "NaN"
bag.weight # => Float::NAN

Values are cast using their to_f method, except for the following strings:

  • Blank strings are cast to nil.

  • "Infinity" is cast to Float::INFINITY.

  • "-Infinity" is cast to -Float::INFINITY.

  • "NaN" is cast to Float::NAN.

Inherits from

Value

Includes

Methods (defined here)

Private methods

(1) Implementation detail — not part of the public API.

Type at least 2 characters to search.

↑↓ navigate · open · esc close