分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

js中的Math

发布时间:2023-09-06 02:32责任编辑:白小东关键词:js

js中的Math

Math.round 取最接近的整数 ??????Math.round(-2.7) // -3Math.ceil 向上取整 ???Math.ceil(1.1) // 2Math.floor 向下取整 ???Math.floor(1.9) // 1Math.trunc 取整 ???Math.trunc(1111.111) // 1111Math.sin 接受的参数是弧度 ???弧度r和角度g的关系 ???r = g*Math.PI/180 ???Math.sin(30*Math.PI/180)Math.cos ???Math.cos(60*Math.PI/180)Math.sqrt 开平方 ???Math.sqrt(4)Math.cbrt 开三次方 ???Math.cbrt(8)Math.pow 次方 ???Math.pow(10,10) ????????// 10000000000 ???10 ** 10 ???????????????// es7的写法 ???Math.pow(16,1 / 4) ?????// 开四次方Math.random 随机数 ???Math.random() ??????????????????????// [0,1)之间的随机数 ???Math.random() * (20 - 10) + 10 ?????// [10,20)之间的随机数 ???Math.random() * (20 - 10 + 1) + 10 ?// [10,20]之间的随机数 ???Math.max 取最大值 ???Math.max(...[2,1,5,0,2]) ???Math.max.apply(Math, [2,1,5,0,2]) Math.min 取最小值 ???Math.min(...[2,1,5,0,2]) ???Math.min.apply(Math, [2,1,5,0,2])Math.atan2 ????取原点到任意点的弧度 ???????var vector = {x: Math.sqrt(3), y: 1}; ???????var dir = Math.atan2(vector.y, vector.x); ???????console.log(dir*180/Math.PI); // 30 ???取任意两点连成的直线的弧度 ???????var line = { ???????????p1: {x: -Math.sqrt(3), y: 0}, ???????????p2: {x: 0, y: 1} ???????} ???????var dir = Math.atan2(line.p2.y - line.p1.y, line.p2.x- line.p1.x); ???????console.log(dir*180/Math.PI); // 30Math.hypot 取n个值的平方和根 ???var p1 = {x: 1, y: 2}; ???var p2 = {x: 3, y: 4}; ???var dis = Math.hypot(p2.x-p1.x, p2.y-p1.y); // 取两点间的距离

js中的Math

原文地址:https://www.cnblogs.com/ye-hcj/p/10349826.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved