整数除法总是被截断 [英] Is integer division always truncated
本文介绍了整数除法总是被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在.NET中,我能否确定两个整数之间的除法结果
总是被截断而不是四舍五入到最近?
示例:
99/50 = 1
问候,Teis
In .NET, can I be sure that the result of a division between two integers
always is truncated rather that rounded to nearest?
Example:
99 / 50 = 1
regards, Teis
推荐答案
是。你也可以得到导致整数除法的余数。
如果你需要舍入,使用浮点除法并舍入结果。
Teis Draiby < TE ************* @ draiby.com>在消息中写道
news:u8 ************** @ TK2MSFTNGP11.phx.gbl ...
Yes. You can also get the remainder that results in an integer division.
If you need rounding, use floating point division and round the result.
"Teis Draiby" <te*************@draiby.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
在.NET中,可以我确定两个整数之间划分的结果总是被截断而不是四舍五入到最近的?
例如:
99/50 = 1
In .NET, can I be sure that the result of a division between two integers
always is truncated rather that rounded to nearest?
Example:
99 / 50 = 1
regards, Teis
啊!那一定是Math.IEEERemainder()
谢谢,Teis
Ah! That must be the Math.IEEERemainder()
Thanks, Teis
我不这么认为。起初我会说是同意你的意见但在机器语言.9999999999999999是1
不是0 16位在这里。换句话说,在纯数学.99999 ... = 1但是机器不能用完无穷大它只能
耗尽允许整数允许的位数。在这种情况下..99999 .... 9 = 1.我们必须测试一下这是确定的但是
似乎是合理的。
-
George Hester
_________________________________
" Marina" <所以***** @ nospam.com>在消息新闻中写道:eT ************** @ tk2msftngp13.phx.gbl ...
I don''t think so. At first I would have said "yes" agreed with you. But in machine language .9999999999999999 is 1
not 0 16 bit here. In other words in pure mathematics .99999... = 1 but the machine cannot run out to infinity it can only
run out to the bits allowed allowed for integers. In this case ..99999....9 = 1. We''d have to test that to be sure but that
seems reasonable.
--
George Hester
_________________________________
"Marina" <so*****@nospam.com> wrote in message news:eT**************@tk2msftngp13.phx.gbl...
是的。你也可以得到导致整数除法的余数。
如果你需要舍入,使用浮点除法并将结果四舍五入。
Teis Draiby < TE ************* @ draiby.com>在消息中写道
新闻:u8 ************** @ TK2MSFTNGP11.phx.gbl ...
Yes. You can also get the remainder that results in an integer division.
If you need rounding, use floating point division and round the result.
"Teis Draiby" <te*************@draiby.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
在.NET中,我能确定两个整数之间划分的结果总是被截断而不是四舍五入到最近?
例如:
99/50 = 1
问候, Teis
In .NET, can I be sure that the result of a division between two integers
always is truncated rather that rounded to nearest?
Example:
99 / 50 = 1
regards, Teis
这篇关于整数除法总是被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文