<span style="font-size:18px;">package dsfa;
import java.util.Scanner;
public class A
{
public static void main(String args[])
{
System.out.println(ceil(1.2));
System.out.println(floor(2.1));
System.out.println(rint(-2.6));
System.out.println(round(2.5));
//注意此时的取值为3
System.out.println(round(-2.6));
}
//向上取整
public static double ceil(double x)
{
return Math.ceil(x);
}
//下取整
public static double floor(double x)
{
return Math.floor(x);
}
//向离它近的一个整数取整,若为中间值的时候,下取整
public static double rint(double x)
{
return Math.rint(x);
}
//四舍五入
public static double round(double x)
{
return Math.round(x);
}
}
</span>
取整方法
最新推荐文章于 2018-03-29 22:18:44 发布