Manuel du didacticiel JAVA
/ Java round() 方法
Java round() 方法
rint() 方法返回一個最接近的int、long型值。
語法
該方法有以下幾種語法格式:
long round(double d)int round(float f)
參數(shù)
d -- double 或 float 的原生數(shù)據(jù)類型
f -- float 原生數(shù)據(jù)類型
返回值
返回一個最接近的int、long型值,方法會指定返回的數(shù)據(jù)類型。
實例
public class Test{public static void main(String args[]){double d = 100.675;double e = 100.500;float f = 100;float g = 90f;System.out.println(Math.round(d));System.out.println(Math.round(e)); System.out.println(Math.round(f)); System.out.println(Math.round(g)); }}
編譯以上程序,輸出結(jié)果為:
10110110090