Java 教程 Java ceil() 方法

sinclair · 2022-05-24 23:03:23 · 热度: 20

ceil() 方法可对一个数进行上舍入,返回值大于或等于给定的参数,类型为双精度浮点型。

语法

该方法有以下几种语法格式:

double ceil(double d)

double ceil(float f)

参数

  • double 或 float 的原生数据类型。

返回值

返回 double 类型,返回值大于或等于给定的参数。

实例

public class Test{ public static void main(String args[]){ double d = 100.675; float f = -90; System.out.println(Math.ceil(d)); System.out.println(Math.ceil(f)); System.out.println(Math.floor(d)); System.out.println(Math.floor(f)); } }

编译以上程序,输出结果为:

101.0
-90.0
100.0
-90.0

查看更多 Java Number & Math 类 相关内容

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册