2 # BigDecimal utility library.
4 # To use these functions, require 'bigdecimal/util'
6 # The following methods are provided to convert other types to BigDecimals:
8 # String#to_d -> BigDecimal
9 # Float#to_d -> BigDecimal
10 # Rational#to_d -> BigDecimal
12 # The following method is provided to convert BigDecimals to other types:
14 # BigDecimal#to_r -> Rational
16 # ----------------------------------------------------------------------
30 class BigDecimal < Numeric
31 # Converts a BigDecimal to a String of the form "nnnnnn.mmm".
32 # This method is deprecated; use BigDecimal#to_s("F") instead.
34 if self.nan? || self.infinite? || self.zero?
38 s,f,y,z = self.frac.split
39 i + "." + ("0"*(-z)) + f
44 class Rational < Numeric
45 # Converts a Rational to a BigDecimal
47 num = self.numerator.to_s
49 nFig = BigDecimal.double_fig*2+1
51 BigDecimal.new(num).div(self.denominator,nFig)