Class: Float
- Inherits:
-
Object
- Object
- Float
- Defined in:
- lib/kgl/kmath.rb
Instance Method Summary collapse
Instance Method Details
#to_r ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kgl/kmath.rb', line 17 def to_r str=self.to_s (decimal,power)=str.split(/e/) (integer,decimal)=decimal.split(/\./) length=decimal.length numerator=integer.to_i*10**length+decimal.to_i denominator=10**length power=power.to_i if power>0 numerator*=10**power else denominator*=10**(-power) end return Rational(numerator,denominator) end |