Module: MuchDecimal
- Includes:
- MuchMixin
- Defined in:
- lib/much-decimal.rb,
lib/much-decimal/version.rb
Defined Under Namespace
Modules: TestHelpers
Constant Summary collapse
- DEFAULT_PRECISION =
2- VERSION =
"0.1.2"
Class Method Summary collapse
Class Method Details
.decimal_to_integer(decimal, precision) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/much-decimal.rb', line 18 def self.decimal_to_integer(decimal, precision) if decimal.respond_to?(:to_f) && !decimal.to_s.empty? base_10_modifier = (10.0**precision) (decimal.to_f * base_10_modifier).round.to_i end end |
.integer_to_decimal(integer, precision) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/much-decimal.rb', line 11 def self.integer_to_decimal(integer, precision) if integer.respond_to?(:to_i) && !integer.to_s.empty? base_10_modifier = (10.0**precision) integer.to_i / base_10_modifier end end |