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