By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Problems in Decimal Package

P: 26
I am having a very strange problem which I am unable to figure out.

I wanted all my data to be printed in decimals and not in exponential terms.

So I am using decimal module.

print "\n GENUINE ACCEPTANCE RATE :\t ", GA/Decimal(users)

Now I have set the precision to 9 and when I try to run in the shell it gives me the correct value but during execution of this program for GA=2 and users = 180,000,000 it still provides me exp answer.

And that too it gives me only for this value . Can anybody explain why this is happening.....

Thanks a lot...
Oct 14 '10 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 624
2/180 million probably has too many leading zeros to fit within the 9 precision limitation, or it is the series of infinitely repeating ones that is larger than 9 precision. Try 2/180,000 as an experiment to see if that works. Then check the .quantize member of the decimal class.
Expand|Select|Wrap|Line Numbers
  1. from decimal import *
  2. getcontext()
  3. Context(prec=9, rounding=ROUND_HALF_UP, 
  4.         capitals=1, flags=[], traps=[Overflow, DivisionByZero,
  5.         InvalidOperation])
  6. x = Decimal(2)
  7. y = Decimal(180000)
  8. result1 = x/y
  9. print result1
  11. print Decimal(result1).quantize(Decimal('.00000001')) 
Oct 14 '10 #2

P: 26

It seems you are right as now both the values that you gave print 1.11E-8 , even when I have set the precision to 28.

IS there any way I can get this to work in decimal way.

Thanks a lot....
Oct 14 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.