您的位置:首页 > 编程语言 > Java开发

Java 取整

2016-04-06 13:33 477 查看
向上取整用Math.ceil(double a)

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

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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: