1.丢弃小数部分,保留整数部分
parseInt(5/2)

2.向上取整,有小数就整数部分加1

Math.ceil(5/2)

3,四舍五入.

Math.round(5/2)

4,向下取整

Math.floor(5/2)

Math 对象的方法

方法 描述
abs(x) 返回数的绝对值
acos(x) 返回数的反余弦值
asin(x) 返回数的反正弦值
atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值
atan2(y,x) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)
ceil(x) 对一个数进行上舍入。
cos(x) 返回数的余弦
exp(x) 返回 e 的指数。
floor(x) 对一个数进行下舍入。
log(x) 返回数的自然对数(底为e)
max(x,y) 返回 x 和 y 中的最高值
min(x,y) 返回 x 和 y 中的最低值
pow(x,y) 返回 x 的 y 次幂
random() 返回 0 ~ 1 之间的随机数
round(x) 把一个数四舍五入为最接近的整数
sin(x) 返回数的正弦
sqrt(x) 返回数的平方根
tan(x) 返回一个角的正切
toSource() 代表对象的源代码
valueOf() 返回一个 Math 对象的原始值

math方法的更多相关文章

  1. javascript 取整,取余数 math方法

    1.丢弃小数部分,保留整数部分 parseInt() 函数可解析一个字符串,并返回一个整数. parseInt(string, radix) 参数 描述 string 必需.要被解析的字符串. rad ...

  2. 较常用的Math方法及ES6中的扩展

    记录下与Math有关的常用方法,如:求最大值.最小值等,或者是保留几位数啥的 1.数据 let floatA = 2.325232; let floatB = 2.3456; let temporar ...

  3. JavaScript 数学 (Math) 方法

    一.Math 方法 1.Math.round(x) 的返回值是 x 四舍五入为最接近的整数: Math.round(7.8); // 返回 8 Math.round(3.3); // 返回 3 2.M ...

  4. 常用Math 方法

    /** * * @authors Your Name (you@example.org) * @date 2016-11-18 11:26:44 * @version $Id$ */ Math.pow ...

  5. js中Number对象与MATH方法整理总结

    W3C的文档: Number 对象属性 属性 描述 constructor 返回对创建此对象的 Number 函数的引用. MAX_VALUE 可表示的最大的数. MIN_VALUE 可表示的最小的数 ...

  6. js中常用的Math方法总结

    1.min()和max()方法 Math.min()用于确定一组数值中的最小值.Math.max()用于确定一组数值中的最大值. alert(Math.min(2,4,3,6,3,8,0,1,3)); ...

  7. JS中常用的Math方法

    1.min()和max()方法 Math.min()用于确定一组数值中的最小值.Math.max()用于确定一组数值中的最大值. alert(Math.min(2,4,3,6,3,8,0,1,3)); ...

  8. es6新增Math方法

    Math.trunc()  用于去除一个数的小数部分,只返回整数部分 Math.trunc(4.1) // 4 Math.trunc(4.9) // 4 Math.trunc(-4.1) // -4 ...

  9. java中常见的math方法

    java.lang.Math :   绝对值: static int abs(int a)  static long abs(long a)  static float abs(float a)  s ...

随机推荐

  1. DES根据键值加密解密

    import java.io.IOException; import java.net.URLEncoder; import java.security.SecureRandom; import ja ...

  2. Android:The connection to adb is down, and a severe error has occured.解决方法一

    在自己机上打安桌虚拟机,竟然提示“The connection to adb is down, and a severe error has occured.please ensure ......” ...

  3. scp

    scp -rp -P22 test.txt root@xxxx:/tmp/ scp -rp -P22 root@xxxx:/tmp/1.txt ./

  4. [NoSQL]验证redis的主从复制

    安装配置redis  http://www.cnblogs.com/myrunning/p/4222385.html 1.1查看当前redis文件 1.2修改配置文件 拷贝配置文件分别为redis_m ...

  5. Chrome浏览器插件推荐大全

    如何下载:http://www.cnplugins.com/devtool/ 提示:下载可能版本过旧,推荐搜索喜爱的插件之后前往官网或者github(编译的时候确保node和npm都是最新的版本).或 ...

  6. 让dede运行php代码和mysql语句

    一.dede运行php代码 举例1: {dede:name runphp='yes'} $str = "hello ";@me = $str;@me .= "world& ...

  7. free一个无效指针

    1. 错误描述:   刚才写了一个删除单链表的结点函数, 参数是 指向链表的指针和链表中指定删除的结点的指针.  当我free这个待删除的结点, 结果报错. 2. 为什么会报错? 我查了查MSDN, ...

  8. 分布式搜索ElasticSearch单机与服务器环境搭建

    从上方插件官网中下载适合的dist包,然后解压.进入bin目录,可以看到一堆sh脚本.在bin目录下创建一个test.sh: bin=/home/csonezp/Dev/elasticsearch-j ...

  9. php课程---Ajax(老师详解)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. WPF 打开文件、文件夹

    打开文件代码: OpenFileDialog openFileDialog = new OpenFileDialog();            openFileDialog.Title = &quo ...