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. mysql in 命令

    SQL: select * from table where id IN (3,6,9,1,2,5,8,7); SQL: select * from table where id IN ($str); ...

  2. 访问google,youtube

    一.找到host文件 windows : C:\windows\system32\drivers\etc mac os: /private/etc linux : /etc 二.修改host文件 ht ...

  3. 用js读写cookie的简单办法

    /* 功能:保存cookies函数 参数:name,cookie名字:value,值 */ function SetCookie(name,value){ var Days = 30*12; //co ...

  4. android api汇集

    参考文章: 知乎-想写个 App 练手,有什么有趣的 API 接口推荐吗? 使用 Espresso 和 Dagger 测试网络服务 http://developer.simsimi.com/apps# ...

  5. [LintCode] Continuous Subarray Sum 连续子数组之和

    Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your cod ...

  6. [LintCode] Happy Number 快乐数

    Write an algorithm to determine if a number is happy. A happy number is a number defined by the foll ...

  7. thinkphp框架3.2的cookie删除问题记录

    在使用框架删除cookie时,发现cookie(null)不起作用.后来查看官网相关信息,看到了讨论http://www.thinkphp.cn/bug/2602.html

  8. java类加载机制

    使用某个类是发生的事情 加载->链接(验证.准备.解析)->初始化->可以使用 加载:将class文件字节码内容加载到内存当中,并将这些静态数据转换成方法区中的运行时数据结构 在堆中 ...

  9. js 获取控制台的错误信息

    适合移动端调试的时候优化的报错使用.缺点是无法打印出多条记录,有方法的同学留言告诉我. <!DOCTYPE html> <html lang="en"> & ...

  10. SpringBoot项目部署与服务配置

    spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat).当然你也可以将项 ...