求其近似值,和ceil相似,注意区别。 floor public static double floor(double a) Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. Special cases: If the argument value is already equal to a mathematical integer, then the result is the same as the argument. If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.Parameters: a - a value. Returns: the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer.
floor
public static double floor(double a)
Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. Special cases:
If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.Parameters:
a - a value.
Returns:
the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer.
floor -- 原意 地板。
数学函数,求一个浮点数的地板,就是求一个最接近它的整数,它的值小于或等于这个浮点数。例如:
Math.floor(0.60) -- 0
Math.floor(0.40) -- 0
Math.floor(5) -- 5
Math.floor(5.1) -- 5
Math.floor(-5.1) -- -6
Math.floor(-5.9) -- -6{} -- 条件语句 if 用的
if (条件) {则} else { 否则};Math.floor(prompt("请您输入吧",“10”))
函数的参数由键盘输入得到。
if(a<18)-- 如果小于18岁 否则
floor -- 原意 地板。
数学函数,求一个浮点数的地板,就是求一个最接近它的整数,它的值小于或等于这个浮点数。例如:
Math.floor(0.60) -- 0
Math.floor(0.40) -- 0
Math.floor(5) -- 5
Math.floor(5.1) -- 5
Math.floor(-5.1) -- -6
Math.floor(-5.9) -- -6{} -- 条件语句 if 用的
if (条件) {则} else { 否则};Math.floor(prompt("请您输入吧",“10”))
函数的参数由键盘输入得到。
if(a<18)-- 如果小于18岁 否则
ceil向上取整,也就是取大于等于参数的整数。
round取最接近参数的整数。结果将舍入为整数:加上 1/2,对结果调用 floor 并将所得结果强制转换为 int 类型。换句话说,结果等于以下表达式的值:
(int)Math.floor(a + 0.5f)
ceil向上取整,也就是取大于等于参数的整数。
round返回最接近参数的 int。结果将舍入为整数:加上 1/2,对结果调用 floor 并将所得结果强制转换为 int 类型。换句话说,结果等于以下表达式的值: (int)Math.floor(a + 0.5f)
Math.ceil 向上取整
例:
System.out.println(Math.floor(123.45)); >> 123
System.out.println(Math.floor(-123.45));>> -124
System.out.println(Math.ceil(123.45)); >> 124
System.out.println(Math.ceil(-123.45)); >> -123
ceil向上取整,也就是取大于等于参数的整数。
round返回最接近参数的整数。结果被舍入为整数:加上1/2,对结果调用floor并将所得结果强制转换为整数。
换句话说,结果等于:(int)Math.floor(a+0.5f)
ceil向上取整,也就是取大于等于参数的整数。
round返回最接近参数的整数。结果被舍入为整数:加上1/2,对结果调用floor并将所得结果强制转换为整数。
换句话说,结果等于:(int)Math.floor(a+0.5f)
Math.ceil 向上取整System.out.println(Math.floor(123.45));
System.out.println(Math.floor(-123.45));
System.out.println(Math.ceil(123.45));
System.out.println(Math.ceil(-123.45));/*
123.0
-124.0
124.0
-123.0
*/
是地板
e.g
9.6地板是9
-9.6地板是-10
同理还有个ceil
相反的叫天花板
ceil是向上取整,也就是说取大于等于参数的整数!
round返回最接近参数的 int。结果将舍入为整数:加上 1/2,对结果调用 floor 并将所得结果强制转换为 int 类型。换句话说,结果等于以下表达式的值: (int)Math.floor(a + 0.5f)
ceil是向上取整,也就是取大于等于参数的整数!
round是取最接近参数的值。加上1/2,然后floor的值。即:
(int)Math.floor(a+1/2)
document.write(Math.floor(400.0244))
</script>
运行结果是400。 <script>
document.write(Math.floor(3.8))
</script>
运行结果是3
document.write(Math.floor(400.0244))
</script>
运行结果是400。 <script>
document.write(Math.floor(3.8))
</script>
运行结果是3
public static double floor(double a)返回最大的(最接近正无穷大)double 值,该值小于或等于参数,并且等于某个整数。特殊情况是:
如果参数值总是等于某个整数,那么结果与该参数相同。
如果参数是 NaN、无穷大、正零或负零,那么结果与参数相同。参数:
a - 一个值。
返回:
最大(最接近正无穷大)浮点值,该值小于或等于该参数,并且等于某个整数。
这帖子是 4 年半前的,还接分呢,要结的话老早就结了!这个帖子是我来 CSDN 以来见到的超级挖坟帖!