Java round() 方法

返回到:Java Number类

round() 方法返回一个最接近的int、long型值。

语法

该方法有以下几种语法格式:

long round(double d)

int round(float f)

参数

  • — double 或 float 的原生数据类型
  • — float 原生数据类型

返回值

返回一个最接近的int、long型值,方法会指定返回的数据类型。

实例

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)); 
	}
}

编译以上程序,输出结果为:

101
101
100
90

返回到:Java Number类

作者:terry,如若转载,请注明出处:https://www.web176.com/java_api/19726.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年5月6日
下一篇 2023年5月6日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注