2007年09月06日 星期四 09:57
ij¸ö×Ö¶ÎÊÇfloatµÄ£¬±È·½Ëµ9.1£¬ÓÃMySQLdbÈ¡³öÀ´ÔõôÊÇ9.0999999999999996£¬ ÓÐûÓбȽϺõĽâ¾ö·½·¨£¿ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070906/1db31a91/attachment-0001.html
2007年09月06日 星期四 10:59
On 9/6/07, leopay <leopay在gmail.com> wrote: > 某个字段是float的,比方说9.1,用MySQLdb取出来怎么是9.0999999999999996, > 有没有比较好的解决方法? 这个跟mysql没关系,计算机不能精确的表示浮点数。其实这种1e-12以内的误差, 一般不会造成什么不良后果吧? 如果你想输出的话,可以这样啊: >>> result = 9.0999999999999996 >>> result 9.0999999999999996 >>> print '%.4f' % result 9.1000 >>> -- Best Regards, Leo Jay
Zeuux © 2025
京ICP备05028076号