当前位置: 首页 > Web前端 > vue.js

你需要知道的是数学函数

时间:2023-03-31 19:20:06 vue.js

js中的数学函数MathMath叫做数学函数,但是属于对象类型typeofMath=>"object"Math是数学函数,它提供了很多操作数的方法。Math常用方法abs取绝对值Math.abs(-10)=>10ceil/floor向上或向下舍入Math.ceil(12.444)=>13//向上Math.ceil(-12.444)=>-12Math.floor(-12.444)=>-13//向下Math.floor(12.444)=>12round舍入Math.round(-10.5)=>10sqrt平方根Math.sqrt(100)=>10pow求幂(n的m次方)Math.pow(n,m)Math.pow(2,10)=>1024max/min求最大值和最小值Math.max(12,23,34,45,56)=>56Math.min(12,23,34,45,56)=>12PI获取圆周率Math.PI=>3.141592653589793random获取0-1之间的随机小数for(vari=0;i<10;i++){console.log(Math.random());}=>VM546:20.04970057257337013VM546:20.6231351064275747VM546:20.5078224023964912VM546:20.8352905252558647VM546:20.6559457705463638VM546:20.8613184309923703VM546:20.560912961148593VM546:20.007279315129435915VM546:20.8116470880389592VM546:20.7306956598107344undefined思考:1-10之间的整数Math.round(Math.random()*(m-n)+n):Getarandomintegerbetweenn-mfor(vari=0;i<10;i++){console.log(数学.round(Math.random()*(69-24)+24));}=>VM675:258VM675:234VM675:264VM675:238VM675:234VM675:236VM675:233VM675:261VM675:233VM675:255undefined