On Jul 27, 3:08 pm, Dave Rose <bitdog... / yahoo.com> wrote:
> i'm comming from BBX (Business Basic).... a new kind of number... like
> Bignum
> ...but Biznum .... where all intermediate calculations are correctly and
> consistently rounded. we have a billing system not written in BBX and
> it's always pennies off due to round off error ... there is value in
> this...because BBX has it and i've never had to worry about round off
> errors

Try this:

# prelude
require 'rational'
require 'bigdecimal'
require 'bigdecimal/util'

# compute
result = Rational(5) / 23 * 13 / 27

# output
precision = 5
result.to_d(precision).to_s("F") # => "0.10467"

precision = 50
result.to_d(precision).to_s("F") # =>
"0.10466988727858293075684380032206119162640901771337"

What this means is that you are working with maximum precision
whenever one of the numbers involved in an operation is a Rational().

At output time you specify the precision you actually need.

Unfortunately, operations from the Math module will still convert
their arguments to and produce floats.

It would be nice if we'd need to require less files to get that
behaviour. I'd also prefer being able to do result.to_s(precision)
over .to_d().to_s().