In my program, decimal accuracy is very important.
A lot of my calculations must be accurate to many decimal places (such as 50).
Because I am using python, I have been using the decimal module
(with context().prec = 99. ie; Set to have 99 decimal places of accuracy when instantiating a decimal object)
as pythonic floats don t allow anywhere near such accuracy.
Since I wish for the User to specify the decimal places of accuracy of the calculations, I ve had to implement several round() functions in my code.
Unfortuneately, the inbuilt round function and the decimal object do not interact well.
round(decimal.Decimal( 2.000000000000000000001 ),50)
# Number is 1e-21. There are 21 decimal places, much less than 50.
Yet the result is 2.0 instead of 2.000000000000000000001
The round function is not rounding to 50. Much less!
Yes, I have made sure that the over-rounding does not occur on instantiation of the Decimal object, but after calling round.
I always pass strings representing floats to the Decimal constructor, never pythonic floats.
Why is the round function doing this to me?
(I realise that it was probably originally designed for pythonic floats which can never have so many decimal places, but the documentation claims that the Decimal object integrates perfectly into python code and is compatible with the inbuilt python functions!)
Thanks profusely!
(This has me quite unnerved, since this problem undermines the use of the entire program)
Specs:
python 2.7.1
Windows 7
decimal module (inbuilt)