<分区>
刚开始学python,偶然发现一个特殊性
python 版本:
Python 2.7.2 (default, Jul 20 2011, 02:32:18) [GCC 4.2.1 (LLVM, Emscripten 1.5, Empythoned)] on linux2
于:http://repl.it/languages/Python
与口译员一起工作:
pi = 3.141 // 3 places decimal precision
#typing pi & pressing return puts 3.141
type(pi)
=> <type 'float'>
pi = 3.1415
type(pi)
=> <type 'float'>
#pi puts 3.1415000000000002
好的,浮点精度因不精确而臭名昭著; 但为什么只有 4 点精度才能得到那个“尾部”?
还有:
pi2 = 3.1415100000000002
pi == pi2 # pi was assigned 3.1415
=> True
print(pi2)
3.14151 # Where's my precision?