转自:
下文笔者将通过示例的方式讲述Math.round方法的功能简介说明,如下所示:
Math.round()方法的功能:
返回一个最接近参数值的数(int,long值)
Math.round()语法:
long round(double d)
int round(float f)
分别用于返回一个最接近的int或long值
例:
package com.java265.other;
public class Test {
public static void main(String[] args) throws Exception {
double d = 88.524;
double e = 88.500;
float f = 88;
float g = 10f;
System.out.println(Math.round(d));
System.out.println(Math.round(e));
System.out.println(Math.round(f));
System.out.println(Math.round(g));
}
}
-------运行以上代码,将输出以下信息----
89
89
88
10