位置:首頁 > 軟件操作教程 > 編程開發(fā) > Java > 問題詳情

Java Math類中取整函數(shù)的方法

提問人:劉旭39發(fā)布時間:2020-11-27

取整函數(shù)方法

Math類中提供了幾種取整方法,如表所示。

82LVHN}U48R$OAAJ)_QE`V4.png

示例如下所示:

//Math類中取整函數(shù)的方法

public class RoundingMethod {

public static void main(String[] args) {

System.out.println("舍掉小數(shù)取整:Math.floor(3.14)=" + Math.floor(3.14)); 

System.out.println("四舍五入取整:Math.rint(-2.5)=" + Math.rint(-2.5)); 

System.out.println("湊整:Math.ceil(3.14)=" + Math.ceil(3.14)); 

System.out.println("四舍五人取整:Math.round( 1.805)=" + Math.round( 1.805));

}

}

(9OK%99~5G18GW0M~8}1YJS.png

繼續(xù)查找其他問題的答案?

相關(guān)視頻回答
回復(0)
返回頂部