Java 取整

向上取整用Math.ceil(double a)spa

向下取整用Math.floor(double a) 
舉例:code

public static void main(String[] args) throws Exception { double a = 35; double b = 20; double c = a / b; System.out.println("c===>" + c); // 1.75 System.out.println("c===>" + Math.ceil(c)); // 2.0 System.out.println(Math.floor(c)); // 1.0 }
相關文章
相關標籤/搜索