Python Forum
Percentages displayed as "0.00"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Percentages displayed as "0.00"
#1
Hello,

This is a simple query where I need to display a quantity, and the percentage it represents.

I don't know if it's a Python or SQLite issue, but for some reason, the percentage column only displays "0.00" for all the rows:

cur.execute("SELECT NUMBER,1.0 * NUMBER / (SELECT SUM(NUMBER) FROM MyTable) AS PERCENTAGE FROM MyTable")
rows = cur.fetchall()
for row in rows:
	output = "{}\t{:.2f}".format(row['NUMBER'],row['PERCENTAGE'])
	print(output)
Can someone spot the error?

Thank you.
Reply


Messages In This Thread
Percentages displayed as "0.00" - by Winfried - Nov-15-2019, 03:27 PM
RE: Percentages displayed as "0.00" - by ibreeden - Nov-15-2019, 04:29 PM
RE: Percentages displayed as "0.00" - by Winfried - Nov-15-2019, 05:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fuzzy Wuzzy how to get my fuzzyratio displayed windingsareuseful 3 449 Apr-04-2024, 05:38 PM
Last Post: deanhystad
  Trying to get counts/sum/percentages from pandas similar to pivot table cubangt 6 1,677 Oct-06-2023, 04:32 PM
Last Post: cubangt
  Table displayed out of order nigelwright7557 3 1,912 Nov-24-2021, 10:07 AM
Last Post: nigelwright7557
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,148 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner
  Auto-copy all displayed "print" results into clipboard? smallabc 1 1,757 Dec-16-2019, 02:10 PM
Last Post: buran

Forum Jump:

User Panel Messages

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