rounding floats to a number of bits - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: rounding floats to a number of bits (/thread-21077.html) |
rounding floats to a number of bits - Skaperen - Sep-12-2019 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? RE: rounding floats to a number of bits - luoheng - Sep-13-2019 >>> 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 RE: rounding floats to a number of bits - Skaperen - Sep-13-2019 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). |