Sha256: 0fcd9e39c594d45957f46a36987ac0ae17dd1fe69e1e1d608d35c71adaaa29a4
Contents?: true
Size: 469 Bytes
Versions: 48
Compression:
Stored size: 469 Bytes
Contents
module Stellar # reopen class class Price MAX_PRECISION = (2**31) - 1 def self.from_f(number) best_r = Util::ContinuedFraction.best_r(number, MAX_PRECISION) new({ n: best_r.numerator, d: best_r.denominator }) end def invert self.class.new(n:d,d:n) end def to_f n / d.to_f end def to_s "#{n} / #{d}" end def inspect "#<Stellar::Price #{self}>" end end end
Version data entries
48 entries across 48 versions & 3 rubygems