| | |
Weird problem with float or double....
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2006
Posts: 6
Reputation:
Solved Threads: 0
simple problem....but I have no clue why its not working.....
For some reason temp is always 0.........I want a double percentage difference between the two values....
Please guys..help me out here......after 500 lines of code ...I am stuck here......my assignment is due tonight.....
how the hell do I get a float value?
Python Syntax (Toggle Plain Text)
if (w[0] > m[1]): temp = ((w[0]-m[1])/w[0])*100 print temp
For some reason temp is always 0.........I want a double percentage difference between the two values....
Please guys..help me out here......after 500 lines of code ...I am stuck here......my assignment is due tonight.....
how the hell do I get a float value?
Hi shafter111,
If you are dividing an integer by some other number and you want the quotient to be a float, you need to cast the integer to a float. In other words: While: If you need greater precision than that provided by float(), look up the decimal module in the tutorial:
Guido van Rossum's Python Tutorial
Hope that helps.
If you are dividing an integer by some other number and you want the quotient to be a float, you need to cast the integer to a float. In other words:
Python Syntax (Toggle Plain Text)
a, b = 8, 3 temp = ((a-b)/a)*100 # Gives you zero
Python Syntax (Toggle Plain Text)
a, b = 8, 3 temp = (float(a-b)/a)*100 # Gives you 62.5
Guido van Rossum's Python Tutorial
Hope that helps.
Vi veri veniversum vivus vici
![]() |
Similar Threads
- C++: problam with data type(int,float,double) (C++)
- Float/Double to String conversion (C)
- problem with Float and Double (C)
- XSLT weird problem... [urgent] (RSS, Web Services and SOAP)
- HELP!!! Weird problem... (C++)
- weird problem : Internet Explorer cannot load all geocities pages (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: problem in finding and replacing a word in python
- Next Thread: Problem extracting values of a Dictionary
| Thread Tools | Search this Thread |
Tag cloud for Python
address alarm anydbm app beginner cipher code coordinates copy cx-freeze data development dictionary directory dynamic examples excel feet file float font format ftp function generator getvalue gui halp handling homework images import input ip itunes java keycontrol line linux list lists loop maintain maze millimeter mouse mysqldb number numbers output parsing path permissions port prime programming projects py2exe pygame pyglet pymailer pyqt python queue random recursion screensaverloopinactive script scrolledtext slicenotation split ssh string strings table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode url urllib urllib2 variable variables ventrilo verify vigenere web webservice windows wx.wizard wxpython xlwt





