android Math類

1、random() 取得一個大於或者等於0.0小於不等於1.0的隨機數 

  1.       System.out.println(Math.random());  //0.08417657924317234  
  2.         System.out.println(Math.random());  //0.43527904004403717  

2、ceil(double a) 返回大於等於a的最小整數

  1.         System.out.println(Math.ceil(-10.1));   //-10.0  
  2.         System.out.println(Math.ceil(10.7));    //11.0  
  3.         System.out.println(Math.ceil(-0.7));    //-0.0  
  4.         System.out.println(Math.ceil(0.0));     //0.0  
  5.         System.out.println(Math.ceil(-0.0));    //-0.0  

3、floor(double a) 返回小於等於a的最大整數

  1.  System.out.println(Math.floor(-10.1));  //-11.0  
  2.         System.out.println(Math.floor(10.7));   //10.0  
  3.         System.out.println(Math.floor(-0.7));   //-1.0  
  4.         System.out.println(Math.floor(0.0));    //0.0  
  5.         System.out.println(Math.floor(-0.0));   //-0.0  

4、max(a,b) 兩個中返回大的值,min(a,b)和它相反

  1.         System.out.println(Math.max(-10.1, -10));   //-10.0  
  2.         System.out.println(Math.max(10.710));     //10.7  
  3.         System.out.println(Math.max(0.0, -0.0));    //0.0 

5、rint(a) 四捨五入,返回double值 

* 注意.5的時候會取偶數  

  1.         System.out.println(Math.rint(10.1));    //10.0  
  2.         System.out.println(Math.rint(10.7));    //11.0  
  3.         System.out.println(Math.rint(11.5));    //12.0  
  4.         System.out.println(Math.rint(10.5));    //10.0  
  5.         System.out.println(Math.rint(10.51));   //11.0  
  6.         System.out.println(Math.rint(-10.5));   //-10.0  
  7.         System.out.println(Math.rint(-11.5));   //-12.0  
  8.         System.out.println(Math.rint(-10.51));  //-11.0  
  9.         System.out.println(Math.rint(-10.6));   //-11.0  
  10.         System.out.println(Math.rint(-10.2));   //-10.0  
6、round(a) 四捨五入,float時返回int值,double時返回long值 
  1.         System.out.println(Math.round(10.1));   //10  
  2.         System.out.println(Math.round(10.7));   //11  
  3.         System.out.println(Math.round(10.5));   //11  
  4.         System.out.println(Math.round(10.51));  //11  
  5.         System.out.println(Math.round(-10.5));  //-10  
  6.         System.out.println(Math.round(-10.51)); //-11  
  7.         System.out.println(Math.round(-10.6));  //-11  
  8.         System.out.println(Math.round(-10.2));  //-10  

7、abs絕對值

  1.         System.out.println(Math.abs(-10.4));    //10.4
  2.         System.out.println(Math.abs(10.1));     //10.1  
8、acos 角的反餘弦,範圍在 0.0 到 pi 之間

9、asin 角的反正弦,範圍在 -pi/2 到 pi/2 之間

10、atan 角的反正切,範圍在 -pi/2 到 pi/2 之間

11、atan2(y,x) 將矩形座標 (x, y) 轉換成極座標 (r, theta)

12、cos(double) 返回角的三角餘弦

13、sin(double)返回角的三角正弦

14、tan(double)返回角的三角正切

15、sqrt(double)返回正確舍入的 double 值的正平方根

16、toDegrees(double)將用弧度測量的角轉換爲近似相等的用度數測量的角

17、toRadians(double)將用度數測量的角轉換爲近似相等的用弧度測量的角

18、pow(double a, double b)返回第一個參數的第二個參數次冪的值

19、exp(double a)返回歐拉數 e 的 double 次冪的值

20、log(double a)返回(底數是 e)double 值的自然對數



發佈了23 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章