Precision of repr(f), str(f), print(f) when f is float
问题 If I run: >>> import math >>> print(math.pi) 3.141592653589793 Then pi is printed with 16 digits, However, according to: >>> import sys >>> sys.float_info.dig 15 My precision is 15 digits. So, should I rely on the last digit of that value (i.e. that the value of π indeed is 3.141592653589793nnnnnn). 回答1: TL;DR The last digit of str(float) or repr(float) can be "wrong" in that it seems that the decimal representation is not correctly rounded. >>> 0.100000000000000040123456 0.10000000000000003