zoukankan      html  css  js  c++  java
  • javaScript系列---【Math函数-基本语法】

    Math数学函数

    Math属于js中的内置对象 (内置对象的方法都是用当前类(Math).出的)

    基本语法:

     Math.方法(参数);

    Math.abs(数据); 取绝对值
    
    Math.floor(数据); 向下取整
    
    Math.ceil(数据);向上取整
    
    Math.max(数据1,数据2,..); 取最大值
    
    Math.min(数据1,数据2,..); 取最小值
    
    Math.pow(n,m); n的m次幂
    
    Math.sqrt(数据); 开方
    
    Math.round(数据);四舍五入
    
    Math.random(); 生成[0-1)之间的随机小数 左闭右开区间 包含0,不包含1

    生成某个范围的随机数 (n-m)

    • Math.round(Math.random()*(m-n)+n);

    console.log(Math.abs(-10));
    console.log(Math.abs(-10.23));
    console.log(Math.abs(10.23));
    • 生成0-n某个范围 Math.round(Math.random()*n)

    console.log(Math.round(Math.random()*(5-0)+0));
            0-10
    • 既包括开始值也包括结束值

     

  • 相关阅读:
    CSRF攻击原理
    大前端
    尊敬自己,才能拥有改变的力量
    重温尼采语录 序章
    人生的弹性 -- 观《聚宝盆》有感
    求学梦
    爱国情怀
    雾中见我
    找东西
    走在路上的感悟
  • 原文地址:https://www.cnblogs.com/chenhaiyun/p/14550771.html
Copyright © 2011-2022 走看看