LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1253|回复: 0

关于格式化输出的转换类型

[复制链接]
发表于 2009-12-19 21:05:56 | 显示全部楼层 |阅读模式
g的定义(来自python帮助文档):
Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
于是我做了几个实验,如下:
>>> print "%g" %(20.00000)
20
>>> print "%g" %(20.0000000000)
20
>>> print "%g" %(20.00000000001)
20
>>> print "%.4g" %(20.00000000001)#这个小数位数大于4按照定义应该使用科学计数法啊,怎么执行结果是20啊。
20
还有下一句(来自python帮助文档)
The alternate form causes the result to always contain a decimal point, and trailing zeroes are not removed as they would otherwise be.

按照这句话的意思,上面的那几个例子输出应该包含小数点啊,怎么都没有小数点,而且执行结果都是20啊,郁闷啊,看不太懂了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表