This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients kenfos, steven.daprano
Date 2021-09-22.10:24:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632306251.43.0.497850696578.issue45263@roundup.psfhosted.org>
In-reply-to
Content
"the expected behaviour is to return a digit with 3 decimal points"

I presume you mean a float with 3 digits after the decimal point. Three decimal points would be a bug :-)

I am afraid that you are misinterpreting what you are seeing. Rounding a number does not force it to display with trailing zeroes. Floats display using the most natural form, which means trailing zeroes are dropped. 0.42 will display as 0.42 not 0.420 or 0.4200 or 0.4200000000.

The number has no idea that you want to display three digits, and cannot know. There is no way for each number to remember that at some point it came from you calling round().

If you need to format the number for display to a fixed size, don't use round, use one of the many different string methods:

>>> num = 0.42
>>> print("x = %.4f" % num)
x = 0.4200
>>> print("x = {:.8f}".format(num))
x = 0.42000000
>>> print(f"x = {num:.12f}")
x = 0.420000000000


This is for reporting bugs, not a help desk. In the future, it is best to check with more experienced programmers before reporting things as a bug. There are many useful forums such as the Python Discuss website, Reddit's r/learnpython, or the Python-List mailing list where people will be happy to help guide you whether you have discovered a bug or not.

https://www.python.org/community/forums/

This is *especially* important when it comes to numeric issues which can be tricky even for experienced coders.
History
Date User Action Args
2021-09-22 10:24:11steven.dapranosetrecipients: + steven.daprano, kenfos
2021-09-22 10:24:11steven.dapranosetmessageid: <1632306251.43.0.497850696578.issue45263@roundup.psfhosted.org>
2021-09-22 10:24:11steven.dapranolinkissue45263 messages
2021-09-22 10:24:11steven.dapranocreate