Android自定義-Math

java Math基礎(chǔ)

主要方法

一般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);//四舍五入 這個(gè)float時(shí)返回int值,double時(shí)返回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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容