zoukankan      html  css  js  c++  java
  • js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结

    Math.round、parseInt、Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结。

    一、Math.round

    作用:四舍五入,返回参数+0.5后,向下取整。

    如:

    Math.round(5.57)  //返回6

    Math.round(2.4)   //返回2

    Math.round(-1.5)  //返回-1

    Math.round(-5.8)  //返回-6

    二、parseInt

    作用:解析一个字符串,并返回一个整数,这里可以简单理解成返回舍去参数的小数部分后的整数。

    如:

    parseInt(5.57)  //返回5

    parseInt(2.4)  //返回2

    parseInt(-1.5)  //返回-1

    parseInt(-5.8)  //返回-5

    三、Math.floor

    作用:返回小于等于参数的最大整数。

    如:

    Math.floor(5.57)  //返回5

    Math.floor(2.4)  //返回2

    Math.floor(-1.5)  //返回-2

    Math.floor(-5.8)  //返回-6

    四、Math.ceil

    作用:返回大于等于参数的最小整数

    Math.ceil(5.57)  //返回6

    Math.ceil(2.4)  //返回3

    Math.ceil(-1.5)  //返回-1

    Math.ceil(-5.8)  //返回-5

    html5
  • 相关阅读:
    MUI(5)
    MUI(4)
    MUI(3)
    如何查找僵尸进程并Kill之,杀不掉的要查看父进程并杀之
    Linux下查看文件和文件夹大小
    CentOS,Ubuntu,Gentoo,Freebsd,RedHat,Debian的区别及选择
    eclipse4.3 安装tomcat8
    maven 代理
    ldap基本命令
    ssh-keygen
  • 原文地址:https://www.cnblogs.com/lixu880/p/6367751.html
Copyright © 2011-2022 走看看