Class | BigDecimal |
In: |
bigdecimal/lib/bigdecimal/util.rb
bigdecimal/bigdecimal.c |
Parent: | Numeric |
**** BigDecimal version ****
/* * **** BigDecimal version **** */ static VALUE BigDecimal_version(VALUE self) { /* * 1.0.0: Ruby 1.8.0 * 1.0.1: Ruby 1.8.1 */ return rb_str_new2("1.0.1"); }
to "nnnnnn.mmm" form digit string Use BigDecimal#to_s("F") instead.
# File bigdecimal/lib/bigdecimal/util.rb, line 35 def to_digits if self.nan? || self.infinite? || self.zero? self.to_s else i = self.to_i.to_s s,f,y,z = self.frac.split i + "." + ("0"*(-z)) + f end end
Convert BigDecimal to Rational
# File bigdecimal/lib/bigdecimal/util.rb, line 46 def to_r sign,digits,base,power = self.split numerator = sign*digits.to_i denomi_power = power - digits.size # base is always 10 if denomi_power < 0 denominator = base ** (-denomi_power) else denominator = base ** denomi_power end Rational(numerator,denominator) end