Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python won 't do decimals
#1
It took me a lot of tries before I was able to figure out the problem, and I was stunned. When building my genealogy website, I display 100 entries per page, but I don't want final pages with only a small handful. If there remain 101 entries I'd rather display 51 on one page and 50 on the next. It should have been simple with

z = (remainder / 2)
z = int(z + 0.6)
However, it makes things worse. It takes the first line and instead of z = 50.5 it says z = 50 and the next line doesn't help. The program puts 50 lines on one page, 50 on the next and then builds a page with one lone entry. I had to work around and say

if remainder % 2 == 1:
     z = z + 1
I don't recall this happening before in the years I've been coding in Python.

What is the way to say I absolutely want a decimal answer to remainder / 2 and also not a string variable because I need to do more math with it ?
Reply


Messages In This Thread
Python won 't do decimals - by SomebodySmart - Jun-08-2023, 10:30 AM
RE: Python won 't do decimals - by deanhystad - Jun-08-2023, 11:11 AM
RE: Python won 't do decimals - by buran - Jun-08-2023, 11:13 AM
RE: Python won 't do decimals - by SomebodySmart - Jun-08-2023, 03:25 PM
RE: Python won 't do decimals - by bowlofred - Jun-08-2023, 03:38 PM
RE: Python won 't do decimals - by buran - Jun-08-2023, 07:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get numpy ceil and floor value for nearest two decimals klllmmm 4 1,444 Jun-07-2023, 07:35 AM
Last Post: paul18fr
  Adding Decimals to classes with OOP + rounding to significant digits (ATM demo) Drone4four 7 2,457 May-04-2022, 06:15 AM
Last Post: Drone4four
  floats 2 decimals rwahdan 3 1,714 Dec-19-2021, 10:30 PM
Last Post: snippsat
  Converting decimals stylingpat 3 2,224 Mar-27-2021, 02:32 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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