On Tue, Sep 18, 2012 at 2:04 PM, raj g. <lists / ruby-forum.com> wrote:
> I am Trying to Round a number in my code which is as follows
>
> -------------------------------------------
> param :a, 2, 5
> param :b, 10, 49
> param :extra1, 0, 3
> @extra2 = @extra1 == 0 ? (1..3).choose : 0
> @extra = [@extra1 , @extra2]
> @coeff = []
> (@extra.size).times{|i| @coeff[i] = @extra[i] == 0 ? (2..3).choose : 1 }
> @num = @extra.last==0 ?
> @extra.sum*Math::log10(@a):@extra.sum*Math::log10(@b)
>
> @den1 = @coeff.first * Math::log10(@a)
> @den2 = @coeff.last * Math::log10(@b)
>
> @answer = @extra.last == 0 ? (-1*@num)/(@den1-@den2) :
> (@num)/(@den1-@den2)
> @answer = (@answer*100).round/100.to_f
>
> ------------------------------------------------
>
> And I am facing an " 'round': Infinity (FloatDomainError)". How can I
> fix it.

Can you print @den1 and @den2 after setting them? If they are equal,
then the divisor will be 0, hence the Infinity error.

1.9.2p290 :023 > a = 1.0/0
 => Infinity
1.9.2p290 :024 > (a * 100).round
FloatDomainError: Infinity
	from (irb):24:in `round'

Jesus.