如方法返回类型所给定的那样,方法round返回最接近的long或int。
此方法具有以下变体-
long round(double d) int round(float f)
这是参数的详细信息-
d - 一种double或float原始数据类型。
f - 浮点原始数据类型。
此方法将返回最接近的long或int(由方法的返回类型指示)到参数。
public class Test { public static void main(String args[]) { double d=100.675; double e=100.500; float f=100; float g=90f; System.out.println(Math.round(d)); System.out.println(Math.round(e)); System.out.println(Math.round(f)); System.out.println(Math.round(g)); } }
这将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/java/number-round.html
来源:LearnFk无涯教程网
101 101 100 90
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)