Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
whole number and fraction
#6
(Mar-15-2019, 10:51 PM)Skaperen Wrote: so fractions.Fraction(1.5) will give me 0.5?

Be careful, 1.5 is a string, so it should be defined appropriately, as follows. Cheers
# ----- frac.py ---------
from fractions import Fraction
print (Fraction('1.5'))
# ------ OUTPUT ---------
# C:\Training>python frac.py
# 3/2
# -----------------------
Reply


Messages In This Thread
whole number and fraction - by Skaperen - Mar-15-2019, 06:59 PM
RE: whole number and fraction - by ichabod801 - Mar-15-2019, 07:10 PM
RE: whole number and fraction - by Skaperen - Mar-15-2019, 10:51 PM
RE: whole number and fraction - by ichabod801 - Mar-16-2019, 02:27 AM
RE: whole number and fraction - by samsonite - Mar-16-2019, 08:48 AM
RE: whole number and fraction - by farhan275 - Mar-16-2019, 12:00 AM
RE: whole number and fraction - by ichabod801 - Mar-16-2019, 03:14 PM
RE: whole number and fraction - by samsonite - Mar-16-2019, 04:59 PM
RE: whole number and fraction - by casevh - Mar-16-2019, 07:03 PM
RE: whole number and fraction - by Skaperen - Mar-16-2019, 07:08 PM
RE: whole number and fraction - by DeaD_EyE - Mar-17-2019, 06:40 AM
RE: whole number and fraction - by Skaperen - Mar-17-2019, 11:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  decimal + fraction ConsoleErrorLogs 2 659 Mar-03-2025, 03:22 PM
Last Post: deanhystad
  method to remove zero digits from fraction in decimal Skaperen 17 6,324 Oct-23-2022, 04:02 AM
Last Post: Skaperen
  Fraction Calculation with Limitations TINMAN01 13 8,130 Dec-22-2020, 04:45 AM
Last Post: bowlofred
  fraction module: can you stop the reducing? qmfoam 1 3,410 Oct-10-2020, 06:10 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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