2007年07月22日 星期日 22:48
大家好, 我想请教一下我需要做一个除法运算。 比如5/7 我怎么让他给我输出保留小数点后面两位阿? -- Best regards Yuri -------------- 下一部分 -------------- 一个HTML附件被移除... URL: http://python.cn/pipermail/python-chinese/attachments/20070722/c91d066e/attachment.html
2007年07月23日 星期一 09:34
float(5)/7 Òª²»µÈpy3kÒ²ÐС£ On 7/22/07, Yuri <yuri.linux在gmail.com> wrote: > > ´ó¼ÒºÃ£¬ > ÎÒÏëÇë½ÌÒ»ÏÂÎÒÐèÒª×öÒ»¸ö³ý·¨ÔËËã¡£ > ±ÈÈç5/7 > ÎÒÔõôÈÃËû¸øÎÒÊä³ö±£ÁôСÊýµãºóÃæÁ½Î»°¢£¿ > -- > Best regards > Yuri > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070723/6e52a5cf/attachment.htm
2007年07月23日 星期一 09:59
¿ÉÒÔʹÓÃÄÚÖÃÄ£¿édecimal£¬¾«È·¿ØÖÆÐ¡Êýµãºó±£ÁôµÄλÊý¡£
from decimal import *
>>> Decimal('7.325').quantize(Decimal('.01'), rounding=ROUND_DOWN)
Decimal("7.32")
>>> Decimal('7.325').quantize(Decimal('1.'), rounding=ROUND_UP)
Decimal("8")
»¹¿ÉÒÔ¿ØÖÆÓÐЧλÊý¡£
>>> import decimal
>>> decimal.getcontext().prec = 2
>>> decimal.Decimal(1)/decimal.Decimal(7)
Decimal("0.14")
>>> decimal.Decimal("0.14") + 3
Decimal("3.1")
>>> float(decimal.Decimal("0.14"))
0.14000000000000001
ÏêÇéÇë²Î¿´Êֲᡣ
ÔÚ07-7-23£¬Tian <askfor在gmail.com> дµÀ£º
>
> float(5)/7
> Òª²»µÈpy3kÒ²ÐС£
>
>
> On 7/22/07, Yuri <yuri.linux在gmail.com> wrote:
>
> > ´ó¼ÒºÃ£¬
> > ÎÒÏëÇë½ÌÒ»ÏÂÎÒÐèÒª×öÒ»¸ö³ý·¨ÔËËã¡£
> > ±ÈÈç5/7
> > ÎÒÔõôÈÃËû¸øÎÒÊä³ö±£ÁôСÊýµãºóÃæÁ½Î»°¢£¿
> > --
> > Best regards
> > Yuri
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070723/d9f92d52/attachment.html
2007年07月23日 星期一 18:56
print "%.02f"%(5.0/7.0) -------------- ä¸ä¸é¨å -------------- ??HTML?????... URL: http://python.cn/pipermail/python-chinese/attachments/20070723/df5a17f4/attachment.htm
Zeuux © 2025
京ICP备05028076号