Python Forum
Rounding to the nearest eight
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rounding to the nearest eight
#1
Basically, I just need to round a number to the nearest eight and by my research the
round()
function cannot do that.
Reply
#2
Divide by 8, round(), multiply by 8.

>>> round(3.9 / 8) * 8
0
>>> round(4.1 / 8) * 8
8
Reply
#3
Thanks! That worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Not rounding to desired decimal places? pprod 2 703 Mar-05-2021, 11:11 AM
Last Post: pprod
  Decimal Rounding error project_science 4 884 Jan-06-2021, 03:14 PM
Last Post: project_science
  rounding and floats Than999 2 710 Oct-26-2020, 09:36 PM
Last Post: deanhystad
  rounding question DPaul 16 1,887 Apr-12-2020, 02:30 PM
Last Post: DPaul
  price + tax rounding mlieqo 11 2,788 Sep-21-2019, 04:53 PM
Last Post: mlieqo
  rounding floats to a number of bits Skaperen 2 905 Sep-13-2019, 04:37 AM
Last Post: Skaperen
  find nearest number d3fi 7 1,778 Aug-26-2019, 09:32 PM
Last Post: ichabod801
  Finding nearest point of a Multidigraph in Python 3.7 stixmagiggins 5 1,643 Aug-24-2019, 08:51 AM
Last Post: ThomasL
  str.format rounding to the left of the decimal ClassicalSoul 2 1,093 Mar-27-2019, 11:12 AM
Last Post: perfringo
  Rounding/Truncating Numbers Trinx 3 1,362 Jan-16-2019, 10:54 PM
Last Post: Trinx

Forum Jump:

User Panel Messages

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