round 也疯狂-VBS 篇

作者:chilleen 来源:ITPOW(原创) 日期:2007-3-27

相关阅读:

Round(expression[, numdecimalplaces])

Numdecimalplaces

可选项。数字表明小数点右边有多少位进行四舍五入。如果省略,则 Round 函数返回整数。

本节中,我们考虑的是省略 Numdecimalplaces 的情况,即四舍五入为整数的情况。

规则:

expression > 0,公平的四舍五入,即当小数为 0.5 时,是舍还是入,要看其舍之后是偶数,还是入之后是偶数,如果舍之后是偶数则舍,如果入之后是偶数则入。

expression < 0,等价于:Round(x) = -Round(Abs(x))。

示例(与 JS 对照):

  • Round(1.4) 结果为:1
  • Round(1.5) 结果为:2
  • Round(1.6) 结果为:2

 

  • Round(2.4) 结果为:2
  • Round(2.5) 结果为:2
  • Round(2.6) 结果为:3

 

  • Round(-1.4) 结果为:-1
  • Round(-1.5) 结果为:-2
  • Round(-1.6) 结果为:-2

 

  • Round(-2.4) 结果为:-2
  • Round(-2.5) 结果为:-2
  • Round(-2.6) 结果为:-3

相关文章