码迷,mamicode.com
首页 > 其他好文 > 详细

Math的round方法

时间:2019-08-08 13:28:44      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:http   输出   ==   pre   https   strong   tar   ===   ati   

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

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方法

标签:http   输出   ==   pre   https   strong   tar   ===   ati   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!