对数字进行四舍五入的方法
使用Math中的round方法
import java.util.*;
public class qwe {
public static void main(String[] args) {
double above = 0.7, below = 0.4;
float fabove = 0.7f, fbelow = 0.4f;
System.out.println("Math.round(above)" + Math.round(above));
System.out.println("Math.round(above)" + Math.round(below));
System.out.println("Math.round(above)" + Math.round(fabove));
System.out.println("Math.round(above)" + Math.round(fbelow));
}
}
结果为:1 0 1 0