Terry J. Reedy <tjre...@udel.edu> added the comment:
The flaw in my_round is that it rounds twice, not once. The first rounding is caused by multiplying by a factor that is not a power of 2. In the case of 2.675, that rounding is up enough to affect the second rounding. >>> format(2.675, ".17f") '2.67499999999999982' >>> format(2.675 *100, ".17f") '267.50000000000000000' In the case of 4.395, the first rounding is down. >>> format(4.395, ".17f") '4.39499999999999957' >>> format(4.395 *100, ".17f") '439.49999999999994316' Even if it had been up, it might not have been enough to affect the outcome, as 57 is a lot farther from 100 than 82. If you want to discuss floating point approximations and rounding further, please post to python-list, not here. ---------- components: -Documentation, FreeBSD, IDLE, Library (Lib), Tests, Windows, macOS versions: -Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39059> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com