java数学方法ceil,java.lang.Math.ceil和floor方法

java.lang.Math.ceil和floor方法

Modifier and Type

方法

描述static double

ceil(double a)

返回最小的(最接近负无穷大) double值,该值大于或等于该参数,并等于某个整数。

static double

floor(double a)

返回小于或等于参数的最大(最接近正无穷大) double值,等于数学整数。

static int

floorDiv(int x, int y)

返回小于或等于代数商的最大(最接近正无穷大) int值。

static long

floorDiv(long x, int y)

返回小于或等于代数商的最大(最接近正无穷大) long值。

static long

floorDiv(long x, long y)

返回小于或等于代数商的最大(最接近正无穷大) long值。

static int

floorMod(int x, int y)

返回 int参数的底模数。

static int

floorMod(long x, int y)

返回 long和 int参数的底模。

static long

floorMod(long x, long y)

返回 long参数的底模数。

ceil(double a)

public class TestCeil {

public static void main(String[] args) {

test();

}

//测试 ceil()方法

public static void test(){

double c1 = Math.ceil(1.23);

double c2 = Math.ceil(1.6);

System.out.println("1.23向上取整"+c1);

System.out.println("1.6向上取整"+c2);

}

}

1.23向上取整2.0

1.6向上取整2.0

floor(double a)

public class TestFloor {

public static void main(String[] args) {

test();

}

//测试 floor()方法

public static void test(){

double c1 = Math.floor(1.23);

double c2 = Math.floor(1.6);

System.out.println("1.23向下取整"+c1);

System.out.println("1.6向下取整"+c2);

}

}

1.23向下取整1.0

1.6向下取整1.0

floorDiv(int a, int b)

public class TestFloorDiv {

public static void main(String[] args) {

test();

}

//测试 floorDiv()方法

public static void test(){

int fd1 = Math.floorDiv(10, 3);

System.out.println("10/3向下取整:"+fd1);

}

}

10/3向下取整3

floorMod(int a, int b)

public class TestFloorMod {

public static void main(String[] args) {

test();

}

//测试 floorMod()方法

public static void test(){

int fm1 = Math.floorMod(10, 3);

System.out.println("10%3向下取整:"+fm1);

}

}

10%3向下取整:1

来源:https://www.cnblogs.com/sweetorangezzz/p/12908594.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值