分裂的结果 [英] results of division

查看:119
本文介绍了分裂的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


在小数点后将除法结果限制为几个

空格的正确方法是什么?我不需要精确的火箭科学。

这是一个例子:


1.775与我需要的一样精确,1.70会做。


谢谢,

布拉德

解决方案

2004年12月9日星期四09:38:55 -0500,Brad Tilley< br ******** @ gmail.com>写道:

将除法结果限制在十进制后的几个空格的正确方法是什么?我不需要精确的火箭科学。
这是一个例子:

1.775与我需要的一样精确,通常情况下,1.70会这样做。



使用新的十进制类型 - < http://www.python.org/doc/2.4/whatsnew/node9.html>。


-

干杯,

Simon B,
si * **@brunningonline.net
http:// www.brunningonline.net/simon/blog/


Brad Tilley< br ******** @ gmail.com>写道:

在小数点后将除法结果限制为仅几个空格的正确方法是什么?我不需要精确的火箭科学。这是一个例子:

1.775和我需要的一样精确,通常情况下,1.70会这样做。




"% .2f"%1.775


在文章< cp ********** @ solaris.cc.vt.edu>,

Brad Tilley< br ******** @ gmail.com>写道:


将除法结果限制在小数后的几个空格的正确方法是什么?我不需要精确的火箭科学。
这是一个例子:

1.775与我需要的一样精确,通常情况下,1.70会这样做。



您有两种选择:手动使用浮点和圆形或使用

新的Decimal类并指定您的精度。但是,如果您将计算限制为
,则在链接多个或两个操作后将会出现错误。你最好的选择是在你的计算结束时只进行四舍五入的结束,这时你可以直接将结果四舍五入到
或者只用于显示(通过使用适当的%格式化。

-

Aahz(aa**@pythoncraft.com)< *> http://www.pythoncraft.com/


19。这种语言不会影响你对编程的看法,不值得知道。b $ b。 --Alan Perlis


Hello,

What is the proper way to limit the results of division to only a few
spaces after the decimal? I don''t need rocket-science like precision.
Here''s an example:

1.775 is as exact as I need to be and normally, 1.70 will do.

Thank you,
Brad

解决方案

On Thu, 09 Dec 2004 09:38:55 -0500, Brad Tilley <br********@gmail.com> wrote:

What is the proper way to limit the results of division to only a few
spaces after the decimal? I don''t need rocket-science like precision.
Here''s an example:

1.775 is as exact as I need to be and normally, 1.70 will do.



Use the new decimal type - <http://www.python.org/doc/2.4/whatsnew/node9.html>.

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/


Brad Tilley <br********@gmail.com> writes:

What is the proper way to limit the results of division to only a few
spaces after the decimal? I don''t need rocket-science like
precision. Here''s an example:

1.775 is as exact as I need to be and normally, 1.70 will do.



"%.2f"% 1.775


In article <cp**********@solaris.cc.vt.edu>,
Brad Tilley <br********@gmail.com> wrote:


What is the proper way to limit the results of division to only a few
spaces after the decimal? I don''t need rocket-science like precision.
Here''s an example:

1.775 is as exact as I need to be and normally, 1.70 will do.



You have two options: use floating point and round manually or use the
new Decimal class and specify your precision. However, if you restrict
your calculations, you will have errors after chaining more than one or
two operations. Your best bet is to perform rounding only at the end of
your calculations, at which point you can either round the result
directly or round for display only (by using appropriate % formatting).
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"19. A language that doesn''t affect the way you think about programming,
is not worth knowing." --Alan Perlis


这篇关于分裂的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆