js中的Math
js中的Math
Math.round 取最接近的整数
Math.round(-2.7) // -3 Math.ceil 向上取整
Math.ceil(1.1) // 2 Math.floor 向下取整
Math.floor(1.9) // 1 Math.trunc 取整
Math.trunc(1111.111) // 1111 Math.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); // 30 Math.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的更多相关文章
- JavaScript -- 时光流逝(四):js中的 Math 对象的属性和方法
JavaScript -- 知识点回顾篇(四):js中的 Math 对象的属性和方法 1. Math 对象的属性 (1) E :返回算术常量 e,即自然对数的底数(约等于2.718). (2) LN2 ...
- js中引用类型Math一些常用的方法和属性
js中有一种引用类型叫做Math,和Global属于单体内置对象,里面有一些非常常用的数学方法和数学常量 常用数学常量 Math.E; // 自然对数的底数Math.LN10 10的自然对数 Math ...
- JS中String,Math常用函数
String对象: 1.length属性 说明:获取字符串的长度 实例: var str="abc"; var i=str.length;//output:3 2.charAt() ...
- JS中的Math.pow(a,b)方法
定义和用法 pow() 方法可返回 x 的 y 次幂的值. 语法 Math.pow(x,y) 参数 描述 x 必需.底数.必须是数字. y 必需.幂数.必须是数字. 返回值 x 的 y 次幂. 说明 ...
- JS中的Math.ceil和Math.floor函数的用法
Math.ceil(x) -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入 Math.floor(x)--返回小于等于数字参数的最大整数,对数字进行下舍入 例如: document. ...
- js 中的 Math.ceil() Math.floor Math.round()
alert(Math.ceil(25.9)); alert(Math.ceil(25.5)); alert(Math.ceil(25.1)); alert(Math.round(25.9)); ale ...
- js中的Math对象
绝对值Math.abs() console.log(Math.abs(-25)); console.log(Math.abs('-25'));//存在隐式转换可以求绝对值 co ...
- js中的函数,Date对象,Math对象和数组对象
函数就是完成某个功能的一组语句,js中的函数由关键字 function + 函数名 + 一组参数定义;函数在定义后可以被重复调用,通常将常用的功能写成一个函数,利用函数可以使代码的组织结构更多清晰. ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结(转)
js中Math.round.parseInt.Math.floor和Math.ceil小数取整总结 Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数 ...
随机推荐
- Educational Codeforces Round 27
期末后恢复性训练,结果完美爆炸... A,题意:2n个人,分成两队,要求无论怎么分配,第一队打赢第二队 #include<bits/stdc++.h> #define fi first # ...
- https://www.adminsub.net/tcp-udp-port-finder/14000 ——查找tcp端口对应的服务 可以看某些端口是否让恶意软件开启
效果: TCP/UDP Port FinderPort number or name:Enter port number (e.g. 21), service (e.g. ssh, ftp) or t ...
- MVC框架中的值提供机制(一)
在MVC框架中action方法中的Model数据的绑定的来源有很多个,可能是http请求中的get参数或是post提交的表单数据,会是json字符串或是路径中的相关数据;MVC框架中针对这些不同的数据 ...
- Flask 分页的简单用法 / flask_sqlalchemy /无刷新翻转页面(原创)
flask_sqlalchemy对象提供分页方法 1. 后台views代码: from models import <table_name> #导入model的对象 @app.route( ...
- 第七次scrum meeting记录
文章负责:张华杰 日期:2017年10月31日 会议地点:主楼主南201 各组员工作情况 团队成员 昨日完成任务 明日要完成任务 赵晓宇 课程列表页面搭建 issue20 课程列表页面搭建(part ...
- css11动态效果
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Android 中Activity,Window和View之间的关系
转自:http://hi.baidu.com/xiaofanqing/blog/item/8261ac114ab14f64cb80c435.html 我这里根据我个人的理解来讲讲我个人对这3个概念的理 ...
- OC-通知+Block
=================================== 一.通知(NSNotification) NSNotification 通知类,这个类中有 NSNotificationCent ...
- 剑指offer--33.丑数
本来用数组做标志位,但是测试数据有第1500个,859963392,惹不起哦 ------------------------------------------------------------- ...
- Asyphre for Delphi Xe4 Demo Running on iPad!
Asyphre 4.0 . customize bitmap with asvf file. compiled done! check the video!