我怎样才能迫使部门浮动?司保持四舍五入到零 [英] How can I force division to be floating point? Division keeps rounding down to 0
本文介绍了我怎样才能迫使部门浮动?司保持四舍五入到零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个整数值 a
和 b
,但是我需要它们的浮点数。我知道 a< b
,我想计算 a / b
,所以如果我使用整数除法总是得到0其余的 a
。
如何强制 c <
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
解决方案
>>> from __future__进口部门
>>> a = 4
>>> b = 6
>>> c = a / b
>>> c
0.66666666666666663
I have two integer values a
and b
, but I need their ratio in floating point. I know that a<b
and I want to calculate a/b
, so if I use integer division I'll always get 0 with a remainder of a
.
How can I force c
to be a floating point number in Python in the following?
c = a / b
解决方案
>>> from __future__ import division
>>> a = 4
>>> b = 6
>>> c = a / b
>>> c
0.66666666666666663
这篇关于我怎样才能迫使部门浮动?司保持四舍五入到零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文