如何在actionscript中舍入数字

时间:2011-07-31 11:54:25

标签: flash actionscript-3 flash-cs4 flash-cs5

如何将数字向上舍入为0.5或使用动作脚本3.0 例如

  • 4.9将四舍五入为5
  • 4.7将四舍五入为4.5
  • 2.4将四舍五入为2.5
  • 2.3将四舍五入为2
谢谢。

2 个答案:

答案 0 :(得分:8)

怎么样

Math.round(2 * number_here) / 2

答案 1 :(得分:0)

z = Math.floor(n);
p = n-z;

if(p<0.25)
    ans=z;
else if(p>0.75)
    ans=z+1;
else
    ans=z+0.5;
相关问题