常见的数学方法

1、怎么让数字保留n位小数?
   数字.toFixed(n);
   var num = 123.567;   num.toFixed(2);
 
2、将字符串转化为数字的方法有哪些? 数学方法有哪些?(Math)
   var str = '123.45';
   parseInt(str);
   parseFloat(str);
   Number(str);
 
3. 随机数:Math.random()  0-1之间;求10到20之间的随机数随机数即:10+Math.random()*20
 
4.  向上取整: Math.ceil();   Math.ceil(4.2)=》5
     向下取整: Math.floor();   Math.floor(4.2)=》4     Math.floor(4.9)=》4   
     四舍五入: Math.round();   Math.round(4.8)=》5
     次方函数: Math.pow(x,y);  x的y次方  Math.pow(5,2) =》五的2次方
原文地址:https://www.cnblogs.com/qiuying/p/7403962.html