9b5e00fcc5
Formerly, py/formatfloat would print whole numbers inaccurately with nonzero digits beyond the decimal place. This resulted from its strategy of successive scaling of the argument by 0.1 which cannot be exactly represented in floating point. The change in this commit avoids scaling until the value is smaller than 1, so all whole numbers print with zero fractional part. Fixes issue #4212. Signed-off-by: Dan Ellis dan.ellis@gmail.com
5 lines
201 B
Python
5 lines
201 B
Python
# check a case where rounding was suppressed inappropriately when "f" was
|
|
# promoted to "e" for large numbers.
|
|
v = 8.888e32
|
|
print("%.2f" % v) # '%.2f' format with e32 becomes '%.2e', expect 8.89e+32.
|