Method: BigDecimal#to_digits

Defined in:
lib/bigdecimal/util.rb

#to_digitsObject

call-seq:

a.to_digits -> string

Converts a BigDecimal to a String of the form “nnnnnn.mmm”. This method is deprecated; use BigDecimal#to_s(“F”) instead.

require 'bigdecimal/util'

d = BigDecimal("3.14")
d.to_digits                  # => "3.14"


90
91
92
93
94
95
96
97
98
# File 'lib/bigdecimal/util.rb', line 90

def to_digits
  if self.nan? || self.infinite? || self.zero?
    self.to_s
  else
    i       = self.to_i.to_s
    _,f,_,z = self.frac.split
    i + "." + ("0"*(-z)) + f
  end
end