Math的round方法


代码如下,后面的注释是输出的结果

public static void main(String[] args) {
        System.out.println(Math.round(0.399));//0
        System.out.println(Math.round(0.4));//0
        System.out.println(Math.round(0.41));//0
        System.out.println(Math.round(0.499));//0
        System.out.println(Math.round(0.5));//1
        System.out.println(Math.round(0.51));//1
        System.out.println(Math.round(0.6));//1
        System.out.println("======================");
        System.out.println(Math.round(-0.6));//-1
        System.out.println(Math.round(-0.51));//-1
        System.out.println(Math.round(-0.5));//0
        System.out.println(Math.round(-0.499));//0
        System.out.println(Math.round(-0.41));//0
        System.out.println(Math.round(-0.4));//0
        System.out.println(Math.round(-0.399));//0
    }

 总结,round的进位是向数轴的右方向进位的,而不是按照数的绝对值进行四舍五入的

关于Math对三角函数表示的一些知识点查看https://blog.csdn.net/River_Continent/article/details/80637952


免责声明!

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



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