What's the maximum number for float on Rails validation?

Viewed 196

I have the following validation:

class Metrics
  validates :verbs_count, allow_nil: true, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: ? }
end

I would like to know what would be the maximum value of a float without losing precision. I know it seems like a question that should be easy to find an answer, but I'm not finding it.

1 Answers

As per the docs (which are not in https://api.rubyonrails.org/ pages, but in the code in master):

Validates whether the value of the specified attribute is numeric by trying to convert it to a float with Kernel.Float (if only_integer is false) or applying it to the regular expression /\A[\+\-]?\d+\z/ (if only_integer is set to true).

Precision of Kernel.Float values are guaranteed up to 15 digits.

The answer you're looking for is maybe here: "Precision of Kernel.Float values are guaranteed up to 15 digits" - as there's not a maximum number, then you can use whatever you want, just having in mind that greather numbers will loose precision.

Related