On Thu, Aug 22, 2013 at 10:55 PM, F=F6ldes L=E1szl=F3 <lists / ruby-forum.com=
>wrote:

> I'm experimenting with arbitrary precision numbers but I ran into a
> precision problem with #power method.
>
> The base:
> > b =3D
>
> BigDecimal("1.03448275862068965517241379310344827586206896551724137931034=
4827586206896551724")
>
> This is nice:
> [65] pry(main)> b.power(4.0001,5).to_s("F")
> =3D> "1.1452"
>
> But this one yields gajilion digits, despite the low precision
> parameter:
> [64] pry(main)> b.power(4.0,5).to_s("F")
> =3D>
>
> "1.1452308205649522608411649683789045655121514645522783730935794966922623=
39862090976570839595577995167
>
> 4087102580162622776520223221039445425509804448302725507967645108521224237=
60853182822668783694175299491
>
> 9982298407563613330486751376044316082575383758364780052058517053335237338=
48357300705094580513261348742578974976"
>
> Using #round solves the problem, but there is clearly a problem. Any
> idea how to properly parameter the method so I don't need to use #round?
> Checking the C source (I'm not a C ninja) it looks that a FLOAT value
> gets converted if it equals with its rounded self which is certainly
> true (although I don't know the precision) if the value is X.0


I would not worry about the number of digits in the BigDecimal instance.
 Internally you should use most precise figures. If you want to do output
then you can apply proper formatting, e.g. with printf.

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/