首页 > 编程语言 > 详细

java 基础知识小结

时间:2015-07-29 18:40:40      阅读:181      评论:0      收藏:0      [点我收藏+]

1. java 有三个求整的函数 

  math.floor ()  (floor 是地板的意思)  向下求整

  math.ceil ()  (ceil 是天花板的意思 ) 向上求整

  math.round()  (round有四舍五入的意思)四舍五入

 

public class A{
    public static void main(String[] args){
        float f =1.1f;
        double d = 2.9;
        System.out.println(Math.ceil(f));
        System.out.println(Math.floor(f));
        System.out.println(Math.round(f));
        System.out.println(Math.ceil(d));
        System.out.println(Math.floor(d));
        System.out.println(Math.round(d));
    }
}

结果为:

2.0

1.0

1.0

3.0

2.0

3.0

 

java 基础知识小结

原文:http://www.cnblogs.com/caoyusongnet/p/4686539.html

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