开发者

How to round number in actionscript

开发者 https://www.devze.com 2023-03-25 09:14 出处:网络
how can I round number to up down or to the 0.5 using action script 3.0 for example 4.9 w开发者_如何转开发ill be rounded to 5

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

  • 4.9 w开发者_如何转开发ill 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.


How about

Math.round(2 * number_here) / 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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号