困惑!! [英] CONFUSED!!

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

问题描述

看看下面的VB代码。第一个MsgBox显示数字2

而第二个是6.为什么?为什么2.5被四舍五入为2和5.5是

四舍五入为6 ??


Dim i As Integer = 5/2


MsgBox(i)


Dim j As Integer = 11/2

MsgBox(j)

Have a look at the follwoing VB-code. The first MsgBox shows the number 2
while the second one 6. WHY? How come 2.5 is rounded off to 2 and 5.5 is
rounded off to 6??

Dim i As Integer = 5 / 2

MsgBox(i)

Dim j As Integer = 11 / 2

MsgBox(j)

推荐答案

如果可能的话,更改为整数除法如果不是从整数类型更改并且

他们尝试舍入,我遇到了同样的问题..令我感到困惑直到我

只用int division解决它而放弃了。


Dim i As Integer = 5 \2


关于为什么圆角差异的答案..我不知道?


" Stefan" < ST ****** @ student.uu.se>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
Change to integer division if possible if not change from integer type and
they try rounding, i ran in to the same problem .. it baffled me till i
solved it using int division only and gave up.

Dim i As Integer = 5 \2

as to your answer of why the rounding difference .. i dunno?

"Stefan" <st******@student.uu.se> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
有一个看看下面的VB代码。第一个MsgBox显示数字2
而第二个显示数字6.为什么?为什么2.5将四舍五入为2而5.5则四舍五入为6 ??

Dim i As Integer = 5/2

MsgBox(i)

Dim j As Integer = 11/2

MsgBox(j)
Have a look at the follwoing VB-code. The first MsgBox shows the number 2
while the second one 6. WHY? How come 2.5 is rounded off to 2 and 5.5 is
rounded off to 6??

Dim i As Integer = 5 / 2

MsgBox(i)

Dim j As Integer = 11 / 2

MsgBox(j)



我忘记了这种类型的舍入的名称,但奇数和偶数数字是不同的。尝试7/2和9/2,并按照处理方式查看

的相似之处。


我会看看我是否可以挖掘关于四舍五入和发布网址的文章。


-

Gregory A. Beamer

MPV; MCP:+ I,SE,SD,DBA


**************************** ********************** ********************

在盒子外面思考!

************************************* ************* ********************

" Stefan" < ST ****** @ student.uu.se>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
I forget the name of this type of rounding, but odd and even numbers are
rounded differently. Try 7/2 and 9/2, as well and see the similarities in
the way it is handled.

I will see if I can dig up the article on rounding and post an URL.

--
Gregory A. Beamer
MPV; MCP: +I, SE, SD, DBA

************************************************** ********************
Think outside the box!
************************************************** ********************
"Stefan" <st******@student.uu.se> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
有一个看看下面的VB代码。第一个MsgBox显示数字2
而第二个显示数字6.为什么?为什么2.5将四舍五入为2而5.5则四舍五入为6 ??

Dim i As Integer = 5/2

MsgBox(i)

Dim j As Integer = 11/2

MsgBox(j)
Have a look at the follwoing VB-code. The first MsgBox shows the number 2
while the second one 6. WHY? How come 2.5 is rounded off to 2 and 5.5 is
rounded off to 6??

Dim i As Integer = 5 / 2

MsgBox(i)

Dim j As Integer = 11 / 2

MsgBox(j)



"斯蒂芬" < ST ****** @ student.uu.se> schrieb
"Stefan" <st******@student.uu.se> schrieb
看看下面的VB代码。第一个MsgBox显示
数字2,而第二个显示第二个6.为什么?为什么2.5四舍五入到
2和5.5四舍五入到6 ??

Dim i As Integer = 5/2

MsgBox(i)

Dim j As Integer = 11/2

MsgBox(j)
Have a look at the follwoing VB-code. The first MsgBox shows the
number 2 while the second one 6. WHY? How come 2.5 is rounded off to
2 and 5.5 is rounded off to 6??

Dim i As Integer = 5 / 2

MsgBox(i)

Dim j As Integer = 11 / 2

MsgBox(j)




数学四舍五入(右词?)意味着转到下一个_even_数字。

-

Armin



Mathematical rounding (right words?) means round to the next _even_ number.
--
Armin


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

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