• Math方法属性操作数字.html


    <script type="text/javascript">
    //在js里面有一个对象Math

    //方法;
    //1.Math.random()
    //返回值:是一个0~0.999999……的随机数
    var res=Math.random()
    document.writeln(res) //0.18934332838003765


    //2.Math.round() 四舍五入取整、只看小数点后的第一位
    //语法:Math.round(数字)
    //返回值:取整后的数字
    var res=Math.round(5.45)
    document.writeln('<br />'+res) //5


    //3.Math.ceil() 向上取整、进1法
    //语法:Math.ceil(数字)
    //返回值:取整后的数字
    var res=Math.ceil(1.1)
    console.log(res) //2


    //4.Math.floor() 向下取整
    //语法:Math.floor(数字)
    //返回值:取整后的数字
    var res=Math.floor(1.9)
    console.log(res) //1


    //5.Math.pow() 取幂
    //语法:Math.pow(数字,多少次幂)
    //返回值:计算好了的数字
    var res=Math.pow(2,3)
    console.log(res) //8



    //6.Math.sqrt() 开平方根
    //语法:Math.sqrt(数字)
    //返回值:开平方后的值
    var res=Math.sqrt(2)
    console.log(res) //1.4142135623730951


    //7.Math.abs() 取绝对值、数值到0之间的距离
    //语法:Math.abs(数字)
    //返回值:取绝对值后的数字
    var res=Math.abs(-12)
    console.log(res) //12


    //8.Math.max() 取最大值
    //语法:Math.max(数字1,数字2,数字3,……)
    //返回值:传递的若干个数字中最大的哪一个
    var res=Math.max(2,3,6,5,4,3,2,0)
    console.log(res) //6


    //9.Math.min() 取最小值
    //语法:Math.min(数字1,数字2,数字3,……)
    //返回值:传递的若干个数字中最小的哪一个
    var res=Math.min(2,3,6,5,4,3,2,0,-10,-11.33)
    console.log(res) //-11.33



    //属性:
    //10.Math.PI 得到PI值 **不需写(),PI是大写**
    var res=Math.PI
    console.log(res) //3.141592653589793

    </script>

  • 相关阅读:
    CF
    求最长反链 || Dilworth 定理
    APIO 2020 补题记录
    CF vp 记录
    虚树
    LCT 学习
    平衡树
    poly
    关于此博客
    题解 P5021【NOIP2018】 【赛道修建】
  • 原文地址:https://www.cnblogs.com/d534/p/12841004.html
Copyright © 2020-2023  润新知