473,385 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problems in Decimal Package

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
2 1462
dwblas
626 Expert 512MB
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
  10.  
  11. print Decimal(result1).quantize(Decimal('.00000001')) 
Oct 14 '10 #2
nk28
26
Hey,

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

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

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
8
by: Georg Brandl | last post by:
Hello c.l.py, what features would you expect of a Python package manager, similar to CPAN or rubygems? I am currently planning to write such a thing, at first privately for myself, and if...
27
by: Gaijinco | last post by:
Sooner or later everytime I found recreational programming challenges I stumble with how I test if a number is has decimal places differnt than 0? For example if I want to know if a number is a...
1
by: Uttam | last post by:
hello, Using Access 2000 with Developer Edition. I used the package and deployment wizard to create an installable version. When I tried out the installation, the installation itself went...
5
by: achraf.b | last post by:
new javascript package to validate data # hasValidChars(string, characters, caseSensitive) # isIP(ip) # isAlpha(string) # isLetter(string) # isNotEmpty(string) #...
4
by: Ivan | last post by:
Hi to all !!! And thanks to answer my topics. I have problems when I try of run stored procedures, show diferents errors. I made one test with one example of the tutorials. The example is this ...
4
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm using greece - greek in my control panel's regional options, and so, my decimal point is the comma (,), while it is the dot (.) for the sql server db, however, I'm facing...
30
kiss07
by: kiss07 | last post by:
Dear Friends, My oracle Version is 9i.my doubts is trigger related question.Anybody clear my doubts.Is possible to create DDL OR TCL OR DML inside trigger use execute immediate statements? ...
17
by: D'Arcy J.M. Cain | last post by:
I'm not sure I follow this logic. Can someone explain why float and integer can be compared with each other and decimal can be compared to integer but decimal can't be compared to float? True...
3
by: capoeira26 | last post by:
I have is that my entered Roman numerals work only if the numerlas are entered in large to smaller format. For exapmple if I type MMC program will correctly display 2100, but when I enter MCM it will...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.