How to round number in actionscript

半世苍凉 提交于 2019-12-13 02:33:51

问题


how can I round number to up down or to the 0.5 using action script 3.0 for example

  • 4.9 will be rounded to 5
  • 4.7 will be rounded to 4.5
  • 2.4 will be rounded to 2.5
  • 2.3 will be rounded to 2

thank you.


回答1:


How about

Math.round(2 * number_here) / 2



回答2:


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;


来源:https://stackoverflow.com/questions/6889312/how-to-round-number-in-actionscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!