Method: Unitwise::Number.coefficify

Defined in:
lib/unitwise/number.rb

.coefficify(value) ⇒ Integer, BigDecimal

Coerces a string-like number to a BigDecimal or Integer as appropriate

Parameters:

  • value

    Something that can be represented as a string number

Returns:

  • (Integer, BigDecimal)


40
41
42
43
44
45
46
47
# File 'lib/unitwise/number.rb', line 40

def self.coefficify(value)
  d = BigDecimal(value.to_s)
  if (i = d.to_i) == d
    i
  else
    d
  end
end