首页 > 其他 > 详细

Math的round方法

时间:2019-08-08 13:30:29      阅读:87      评论:0      收藏:0      [点我收藏+]

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

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

Math的round方法

原文:https://www.cnblogs.com/kitor/p/11320302.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!