JAVA-Tutorial-Handbuch
/ Java round() 方法
Java round() 方法
rint() 方法返回一個(gè)最接近的int、long型值。
語(yǔ)法
該方法有以下幾種語(yǔ)法格式:
long round(double d)int round(float f)
參數(shù)
d -- double 或 float 的原生數(shù)據(jù)類(lèi)型
f -- float 原生數(shù)據(jù)類(lèi)型
返回值
返回一個(gè)最接近的int、long型值,方法會(huì)指定返回的數(shù)據(jù)類(lèi)型。
實(shí)例
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