Module: CMDx::Coercions::BigDecimal
Overview
Converts various input types to BigDecimal format
Handles conversion from numeric strings, integers, floats, and other values that can be converted to BigDecimal using Ruby’s BigDecimal() method.
Constant Summary collapse
- DEFAULT_PRECISION =
14
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ BigDecimal
Converts a value to a BigDecimal.
Instance Method Details
#call(value, options = {}) ⇒ BigDecimal
Converts a value to a BigDecimal
34 35 36 37 38 39 |
# File 'lib/cmdx/coercions/big_decimal.rb', line 34 def call(value, = {}) BigDecimal(value, [:precision] || DEFAULT_PRECISION) rescue ArgumentError, TypeError type = Locale.t("cmdx.types.big_decimal") raise CoercionError, Locale.t("cmdx.coercions.into_a", type:) end |