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 exactly0.5 , theCLng function rounds to the closest even number. For example,0.5 rounds to0 ,1.5 rounds to2 , and3.5 rounds to4 . 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 theFix andInt functions, which truncate, rather than round, the fractional part of a number.