Python Forum

Full Version: precision error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I make 24/48 to equal 0.5?
My program says that it equals 0. However, if I write it as 24.0/48 then I get the correct result.

How do I change this so that my variables will have more precision? I want to write y as 24. I don't want to write it at 24.0


import math
from PIL import Image
import time
y = 24.0
x = 48
z = y / x

print z

a = 24
b = 48
c = a / b
print c
You can use Python 3 instead, or if you prefer Python 2, you can add from __future__ import division at the top of your script.