java 向上、向下取整,四舍五入


public class MathTest {

    public static void main(String[] args) {

        // 四舍五入
        long round = Math.round(1.499);
        long round2 = Math.round(1.5);
        System.out.println(round);
        System.out.println(round2);

        // 向上取整
        int s = (int)Math.ceil(1.1);
        System.out.println(s);

        // 向下取整
        System.out.println((int)Math.floor(1.6));
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM