将数字转化成拥有X小数位的形式

   1: function roundTo(base,precision)
   2:     {
   3:         var m=Math.pow(10,precision);
   4:         var a=Math.round(base*m)/m;
   5:         return a;
   6:     }

 

math.round函数 将数字转化为最接近的整数。

btw:向下取整的函数math.floor 或者math.ceil

posted @ 2008-05-12 16:51  looping  阅读(173)  评论(0编辑  收藏  举报