Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
precision error
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gmpy2 Newbie Working on Precision charlesrkiss 5 488 Jan-23-2024, 04:23 PM
Last Post: charlesrkiss
  Precision with Decimal Type charlesrkiss 9 635 Jan-18-2024, 06:30 PM
Last Post: charlesrkiss
  Precision conversion garynewport 2 899 Oct-19-2022, 10:47 AM
Last Post: garynewport
Photo Filtering data and precision during calculations Scientifix 0 1,763 Mar-30-2021, 01:00 PM
Last Post: Scientifix
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,047 Mar-29-2021, 02:57 PM
Last Post: Marbelous
  Decimal (Global precision setting) Valentina 3 3,588 Aug-23-2019, 11:53 AM
Last Post: Valentina
  python decimal scale precision massimo_m 5 5,312 Aug-22-2019, 11:47 AM
Last Post: perfringo
  Trouble with decimal precision Cassie 4 3,081 Feb-14-2019, 08:23 PM
Last Post: Cassie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020