java android Math常用方法:取最大值,最小值,絕對值...
java Math常用的方法:
Math.abs 求絕對值
Math.ceil 得到不小於某數的最大整數
Math.floor 得到不大於某數的最大整數
例如:Math.floor(12.7) =12.0
Math.ceil(12.7) =13.0
ceil是天花板,即向上取整。floor是地板,向下取整。
Math.IEEEremainder 求餘
Math.max 求兩數中最大
Math.min 求兩數中最小
Math.sqrt 求開方
Math.sqrt(x):平方根
Math.pow(x,y):x的y次方
Math.rint 求距離某數最近的整數(可能比某數大,也可能比它小)
Math.round 同上,返回int型或者long型(上一個函數返回double型)
Math.random 返回0,1之間的一個隨機數