forked from fixin.me/fixin.me
Change Unit.multiplier type from decimal to float
Remove remnants related to BigDecimal.
This commit is contained in:
@@ -103,15 +103,19 @@ module ApplicationHelper
|
||||
def number_field(method, options = {})
|
||||
attr_type = object.type_for_attribute(method)
|
||||
case attr_type.type
|
||||
when :decimal
|
||||
when :float, :double
|
||||
options[:value] = object.public_send(method)&.to_scientific
|
||||
options[:step] ||= BigDecimal(10).power(-attr_type.scale)
|
||||
options[:max] ||= BigDecimal(10).power(attr_type.precision - attr_type.scale) -
|
||||
options[:step]
|
||||
options[:min] = options[:min] == :step ? options[:step] : options[:min]
|
||||
options[:min] ||= -options[:max]
|
||||
options[:size] ||= attr_type.precision / 2
|
||||
when :float
|
||||
options[:step] ||= :any
|
||||
options[:min] ||= Float::MIN_15
|
||||
options[:max] ||= Float::MAX_15
|
||||
# Longest possible number (written not using exponent):
|
||||
# sign (1), leading 0 (1), dot (1), exponent 0s (307), digits (15).
|
||||
# This is only upper bound, which cannot guarantee the number won't fall
|
||||
# out of range.
|
||||
# TODO: add `[pattern]` to limit precision and (possibly) replace `[maxlength]`?
|
||||
# NOTE: `[pattern]` is unavailable on `input[type=number]` and `[min]/[max]` is
|
||||
# unavailable on `input[type=text]`.
|
||||
options[:maxlength] ||= 3 + Float::MIN_10_EXP + Float::DIG
|
||||
options[:size] ||= 6
|
||||
end
|
||||
super
|
||||
|
||||
Reference in New Issue
Block a user