Python Forum
rounding floats to a number of bits
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rounding floats to a number of bits
#1
the round() function works on rounding to a number of decimal digits. is there a way to round a float to a number of bits?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
>>> round(3.567, 2) # the second para is number of bits round
3.57
>>> round(3.56784, 4) 
3.5678
# care with round
>>> round(3.5)
4
>>> round(4.5)
4
Reply
#3
my documentation (for version 3.7.4) says that the 2nd argument of round() is the number of decimal digits (e.g. a reciprocal of a power of 10.0). but, i want bits (e.g a reciprocal of a power of 2.0).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,151 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  When is it safe to compare (==) two floats? Radical 4 816 Nov-12-2023, 11:53 AM
Last Post: PyDan
  need help rounding joseph202020 7 1,403 Feb-21-2023, 08:13 PM
Last Post: joseph202020
  from numpy array to csv - rounding SchroedingersLion 6 2,301 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  How to rotate bits ? korenron 2 1,682 Mar-23-2022, 04:05 PM
Last Post: Larz60+
  floats 2 decimals rwahdan 3 1,676 Dec-19-2021, 10:30 PM
Last Post: snippsat
  From list of bits to PDF drimades 1 1,961 Nov-02-2021, 08:55 PM
Last Post: Gribouillis
  Random data generation sum to 1 by rounding juniorcoder 9 3,573 Oct-20-2021, 03:36 PM
Last Post: deanhystad
  Rounding issue kmll 1 1,450 Oct-08-2021, 10:35 AM
Last Post: Yoriz
  Not rounding to desired decimal places? pprod 2 2,610 Mar-05-2021, 11:11 AM
Last Post: pprod

Forum Jump:

User Panel Messages

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