vb整数除法 运算符 \

在vb6.0中,为什么 100\1.5的结果是50,但是 100\2.5的结果还是50?0.5是舍去还是进1???????

不光在VB6.0中,我在VB2008中也是一样,原因如下:

运算符"\"的含义为:将两个数相除并返回以整数形式表示的结果。
在执行除法之前,Visual Basic 尝试将所有浮点数值表达式转换为 Long。转换为 Long 服从“四舍六入五成双”。
所谓“四舍六入五成双”,是指将一个非整数值转换为整型(或长整型)时,转换函数将移除小数部分,并将该值舍入为最接近的整数。如果小数部分正好是 0.5,转换函数将其舍入为最接近的偶数整数。例如,0.5 舍入为 0,1.5 和 2.5 都舍入为 2。这被称为“四舍六入五成双”,其目的是弥补在将许多这样的数字相加时可能会累积的偏量。

更多详情,请参考MSDN文档。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-11-27
100 \ 1.5 中 1.5 被进位 成 2
100 \ 2.5 中 2.5 被舍成 2

四舍六入,五留双 :0.4直接舍去,0.6直接进位,
0.5 的话 前一位是双数就舍,前一位是单数就入本回答被提问者采纳
第2个回答  2009-04-08
一楼正解!!四舍六入,五留双,这对你很有帮助的。
第3个回答  2009-04-08
在加减乘除运算中,运算结果的类型和运算量的类型相同,由于类型不同,所以出错,要达到你目的可以1000\15 1000\25,由于1.5 2.5是小数所以强制转换时出错
第4个回答  2009-04-08
这段话最能说明白问题:
\ Operator

Used to divide two numbers and return an integer result.

Syntax

result = number1\number2

The \ operator syntax has these parts:

Part Description
result Required; any numeric variable.
number1 Required; any numeric expression.
number2 Required; any numeric expression.

Remarks

Before division is performed, the numeric expressions are rounded to Byte, Integer, or Long expressions.

Usually, the data type of result is a Byte, Byte variant, Integer, Integer variant, Long, or Long variant, regardless of whether result is a whole number. Any fractional portion is truncated. However, if any expression is Null, result is Null. Any expression that is Empty is treated as 0.

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网