Message358822
@adelsonllima: Take a look at the documentation that I linked to for the round function, and in particular this note:
"The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float. See Floating Point Arithmetic: Issues and Limitations for more information."
As Jörn Heissler observed, the issue here is that the numeric literal 9.925 in the source gets turned into a float whose exact value is just slightly larger than 9.925 (because 9.925 can't be exactly represented in the IEEE 754 binary64 floating-point format that your machine is almost certainly using). So because it's a touch larger than 9.925, it rounds up when rounding to two decimal places.
Closing again here: believe it or not, round is working as designed here. |
|
Date |
User |
Action |
Args |
2019-12-23 15:39:44 | mark.dickinson | set | recipients:
+ mark.dickinson, joernheissler, adelsonllima |
2019-12-23 15:39:44 | mark.dickinson | set | messageid: <1577115584.61.0.518009540188.issue39124@roundup.psfhosted.org> |
2019-12-23 15:39:44 | mark.dickinson | link | issue39124 messages |
2019-12-23 15:39:44 | mark.dickinson | create | |
|