关于vbscript:clng / cint / round在VBS和Classic ASP和VBA中出现错误的回合

clng/cint/round in VBS and Classic ASP and VBA wrong round

如果整数部分为奇数而小数部分为5,则四舍五入时为什么ASP和VBS也会使结果下降,即使结果上升呢?

请自己尝试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
a=1.5
wscript.echo clng(a)   '---> 2

a=2.5
wscript.echo clng(a)   '---> 2

a=3.5
wscript.echo clng(a)   '---> 4

a=4.5
wscript.echo clng(a)   '---> 4

a=5.5
wscript.echo clng(a)   '---> 6

a=6.5
wscript.echo clng(a)   '---> 6

这怎么可能? 我没有找到任何有关此的文档...

抱歉,问题是为什么要使用默认VBS / ASP和VBA usr Banker进行四舍五入?


From The Microsoft Developer Network
When the fractional part of a value is exactly 0.5, the CLng function rounds to the closest even number. For example, 0.5 rounds to 0, 1.5 rounds to 2, and 3.5 rounds to 4. The purpose of rounding to the
closest even number is to compensate for a bias that could accumulate when many numbers are added together.

CLng differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number.