|
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啊,郁闷啊,看不太懂了 |
|