java.lang.Math.round方法

java.lang.Math.round方法

Modifier and Type 方法 描述
static long round(double a) 返回最接近 long的参数,其中 long四舍五入为正无穷大。
static int round(float a) 返回最接近的参数 int ,其中 int四舍五入为正无穷大。

round(float a)

public class TestRound {
    public static void main(String[] args) {
        test();
    }
    //测试  round(float a)方法
    public static void test(){
        long r1 = Math.round(1.4);
        long r2 = Math.round(1.5);
        System.out.println("1.4四舍五入值:"+r1);
        System.out.println("1.5四舍五入值:"+r2);
    }
}
1.4四舍五入值:1
1.5四舍五入值:2

round(double a)类似

原文地址:https://www.cnblogs.com/sweetorangezzz/p/12908515.html