Java使四捨五入和保留N位小數的方法

1.若是隻是四捨五入保留整數,能夠用比較簡單的方式web //取整四捨五入 double num1=3.5415; long round = Math.round(num1); System.out.println(round); 輸出結果svg 4 2.若是是小數四捨五入,須要保留N爲小數,可使用BigDecimal的setScale(int newScale, int roundingMode
相關文章
相關標籤/搜索