I’m trying to do some basic math multiplication, division, etc., in Python, but I can’t figure out how to get the correct answers for some problems such as 1/20000 or 38/24000. Python gives 0 as the answer yet I’m looking for 0.00005. I’ve looked at the math module and decimal module a little each but couldn’t find what I’m looking for. Thanks for any help!
Can you share a screenshot of what you’re doing?
You can try
float(1) / float(20000) to ensure that your result is a float.
In Python 2, / is integer division if both inputs are integers - i.e. it’ll give you an integer as a result.
You can change it by making one of them floats.
1.0 / 20000
The decimal point will make Python treat it as a float rather than int.
Hope that helps
I knew there was something super simple that I was forgetting! I could not think of what I was forgetting no matter how hard I tried to think of what it was! lol Thanks everyone!