1、小数取整

  1. public class Test{
  2. public static void main(String args[]){
  3. double d = 100.675;
  4. float f = -90;
  5. System.out.println(Math.ceil(d));
  6. System.out.println(Math.ceil(f));
  7. System.out.println(Math.floor(d));
  8. System.out.println(Math.floor(f));
  9. }
  10. }
  11. // 输出
  12. 101.0
  13. -90.0
  14. 100.0
  15. -90.0

Math.ceil 向上取整
Math.floor 向下取整