美文网首页
Android自定义-Math

Android自定义-Math

作者: 就爱烫卷发 | 来源:发表于2019-06-09 21:28 被阅读0次

java Math基础

主要方法

一般Math.xxx()返回的值都为double类型

  1. Math.sqrt(16); 即开平方 ==4.0

  2. Math.cbrt(8); 即开立方 ==2.0

  3. Math.pow(2,4); 即2^4 = 16.0

  4. Math.max(2.3,4.5) 取大值 4.5

  5. Math.min(2.3,4.5) 取小值 2.3

  6. Math.ceil(-0.9); // 0.0

    /** -2      -1      0      1      2      3
     *     -1.6    --->Math.ceil(-1.6) == -1.0
     *                     0.6 ----Math.ceil = 1.0
     */
    
  7. Math.floor(2.3);//2.0

  8. Math.rint(10.1);//四舍五入

  9. Math.round(12.50);//四舍五入 这个float时返回int值,double时返回long值

  10. Math.sin(30Math.PI/180) 这里Math.PI = π 即 301° ==30°;直接打印为 0.4999999999994

update--------
11.Math.toRadians() --------> Math.sin(Math.toRadians(30)) = 1/2

12 Math.hypot(double x ,double y) ------> Math.hypot(3,4) =5

相关文章

网友评论

      本文标题:Android自定义-Math

      本文链接:https://www.haomeiwen.com/subject/fmhoxctx.html