public class CeilAndFloor {
public static void main(String[] args) {
/*
这两个宝贝函数的主要任务是截掉小数以后的位数.
区别是: floor总是把数字变得越来越小,而ceil总是把数字变大。
其实名字可以理解floor是地板,ceil是天花板。
*/
System.out.println("==============Math.floor()==============");
System.out.println("Math.floor(99.1) = " + Math.floor(99.1));
System.out.println("Math.floor(-99.1) = " + Math.floor(-99.1));
System.out.println("Math.floor(99.9) = " + Math.floor(99.9));
System.out.println("Math.floor(99.9) = " + Math.floor(-99.9));
System.out.println("\n\n==============Math.ceil()==============");
System.out.println("Math.ceil(99.1) = " + Math.ceil(99.1));
System.out.println("Math.ceil(-99.1) = " + Math.ceil(-99.1));
System.out.println("Math.ceil(99.9) = " + Math.ceil(99.9));
System.out.println("Math.ceil(99.9) = " + Math.ceil(-99.9));
}
}
结果
==============Math.floor()==============
Math.floor(99.1) = 99.0
Math.floor(-99.1) = -100.0
Math.floor(99.9) = 99.0
Math.floor(99.9) = -100.0
==============Math.ceil()==============
Math.ceil(99.1) = 100.0
Math.ceil(-99.1) = -99.0
Math.ceil(99.9) = 100.0
Math.ceil(99.9) = -99.0
posted on 2012-01-05 09:20
RoyPayne 阅读(358)
评论(0) 编辑 收藏 所属分类:
java高级