Java round()方法有哪些功能呢?
Java round()方法的功能
round()方法的功能:用于返回同参数(long或int类型)最近的值
round()方法的语法
以下是round()方法的另类写法
long round(double d)
int round(float f)
参数
d-double或float原始数据类型f- 浮点原始数据类型
返回值
- 此方法返回最接近的
long或int类型值,使用方法指定返回类型来返回参数
例
public class testClass {
public static void main(String args[]) {
double a = 88.567;
double b = 99.600;
float c= 98;
float d= 100f;
System.out.println(Math.round(a));
System.out.println(Math.round(b));
System.out.println(Math.round(c));
System.out.println(Math.round(d));
}
}
/*
以上代码运行后,将输出以下信息
89
100
98
100
*/版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


