5.Math对象

 

 (1)算数值:

<script type="text/javascript">
    Math.PI; //圆周率
    Math.E; //算数常量e,即自然对数的底数
    Math.SQRT2; //2的平方根
    Math.SQRT1_2; //1/2的平方根
    Math.LN2; //2的自然对数
    Math.LN10; //10的自然对数
    Math.LOG2E; //以2为底的e的对数
    Math.LOG10E; //以10为底的e的对数
< /script>

(2)数值取整:

<script type="text/javascript">
    Math.ceil(3.14); //向上取整。    输出:4
    Math.floor(3.14); //向下取整。    输出:3
    Math.round(3.14); //四舍五入。    输出:3
< /script>

(3)随机数:

(4)三角函数:

<script type="text/javascript">
    Math.cos(x); //余弦
    Math.acos(x); //反余弦
    Math.sin(x); //正弦
    Math.asin(x); //反正弦
    Math.tan(x); //正切
    Math.atan(x); //反正切
< /script>

(5)其他方法:

<script type="text/javascript">
    Math.max(x,y); //最大值
    Math.min(x,y); //最小值
    Math.abs(x); //绝对值
    Math.pow(x,y); //x的y次幂
    Math.atan2(y,x); //从x轴到点(x,y)的角度
    Math.exp(x); //e的指数
    Math.log(x); //x的自然对数,底为e
    Math.valueOf(); //返回Math对象的原始值
< /script>

 

posted @ 2022-08-24 18:19  cjl2019  阅读(10)  评论(0编辑  收藏  举报