I have to do a calculation with 1/50000. When I do
float(1/50000)
in python it only returns me 0.0. How can I get the actual value in the powers in python? I would like to get 2.5*10^(-5).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note the
.0. It makes sure1.0is a floating-point literal and not an integer one.A different way to write this is as follows:
What you have right now first uses integer division to compute
1/50000. The result of this division is the integer0, which is then converted to a floating-point value (0.0).Finally, note that your current code will behave correctly in Python 3 (and the
float()is superfluous). This is due to PEP 238.