首页 > 试题广场 >

Math.round(-2019.5)的结果是

[单选题]
Math.round(-2019.5)的结果是
  • 2019
  • -2019
  • 2020
  • -2020
Math.round()函数返回一个数字四舍五入后最接近的整数
如果参数的小数部分大于0.5,四舍五入到相邻的绝对值更大的整数
如果参数的小数部分小于0.5,四舍五入到相邻的绝对值更小的整数
如果参数的小数部分等于0.5,四舍五入到相邻的在正无穷(+∞)方向上的整数。

例:
x=Math.round(2019.49) ;      //2019
x=Math.round(2019.5);         //2020
x=Math.round(-2019.5);        //-2019
x=Math.round(-2019.51);      //-2020

发表于 2019-09-04 15:14:17 回复(4)
math.round() 方法,原来的数字加上0.5,再向下取整 https://blog.csdn.net/zhoushumin157016/article/details/51984436
发表于 2020-05-14 13:18:59 回复(6)
本地主要考察Math的几个取整方法,
Math.ceil  向上取整
Math.floor  向下取整
Math.round  四舍五入取整
发表于 2020-02-11 10:12:30 回复(0)
round() 方法可把一个数字舍入为最接近的整数。
发表于 2019-08-07 08:43:09 回复(0)
看到不定项选择我就选了两个,我去😭
发表于 2021-03-06 15:53:39 回复(0)
Math.ceil  向上取整 例子:Math.ceil(-5.9) -5  Math.ceil(5.1) 6
Math.floor  向下取整 例子:Math.ceil(-5.9) -6  Math.ceil(5.1)  5
Math.round  四舍五入取整 例如,3.5 将舍入为 4,而 -3.5 将舍入为 -3。
发表于 2020-09-16 18:23:12 回复(0)
我选B,提示我是多选题,可没说是不定项选择。Math.round()方法,如果传入的数字小数点刚好是.5就选靠近正无穷一端的整数,如:-2019.5取-2019,5.5取6
发表于 2021-11-16 08:20:32 回复(0)
不能理解的,可以画数轴,左边为负 1、Math.ceil  向上取整  例子:Math.ceil(-5.9) -5  Math.ceil(5.1) 6 解析:-5比-5.9大,因为要向上取整,即往大的那个方向取整,所以Math.ceil(-5.9)等于-5;6比5.1大,所以Math.ceil(5.1)等于6 2、Math.floor  向下取整 例子: Math.ceil(-5.9) -6  Math.ceil(5.1)  5 3、Math.round  四舍五入取整 ,五入也是往大的方向取整, 例如,3.5 将舍入为 4,而 -3.5 将舍入为 -3。
编辑于 2021-11-23 15:33:15 回复(0)
Math.round(11.5)的返回值是12,Math.round(-11.5)的返回值是-11。
发表于 2021-04-25 20:07:56 回复(0)
x=Math.round(2019.49) ;      //2019 x=Math.round(2019.5);         //2020 x=Math.round(-2019.5);        //-2019 x=Math.round(-2019.51);      //-2020
发表于 2021-03-18 23:18:24 回复(0)
第一次遇到负数的四舍五入取整,原来是这样
发表于 2021-04-07 12:52:56 回复(0)
console.log(Math.round(-4.5));//-4 console.log(Math.round(-9.1));//-9 console.log(Math.round(-10.6));//-11 console.log(Math.round(0.6));//1 console.log(Math.round(-0.5));//0
发表于 2022-10-08 08:39:31 回复(0)
Math.round()函数返回四舍五入到最接近整数的数值,如果参数的小数部分大于 0.5,则将参数四舍五入为具有下一个更高绝对值的整数。如果小于 0.5,则将参数四舍五入为绝对值较小的整数。如果小数部分正好是 0.5,则参数将舍入到 +∞ 方向上的下一个整数。
发表于 2022-09-16 09:51:09 回复(0)
“四舍六入”:Math.round()的原理是对传入的参数+0.5之后,再向下取整(取比它小的第一个整数或者和它相等的整数)得到的数就是返回的结果,返回值为long型
Math.round(1.0) // 1.5->1
Math.round(1.4) // 1.9->1
Math.round(1.5) // 2->2
Math.round(1.6) // 2.1->2

Math.round(-1.0) // -0.5->-1
Math.round(-1.4) // -0.9->-1
Math.round(-1.5) // -1.0->-1
Math.round(-1.6) // -1.1->-2
发表于 2022-08-04 16:25:16 回复(0)
Math.round()四舍五入取整函数,当参数(正数),分为如下2种情况: (1)小数点后的数>=0.5,则+1取整,如1.5,1.5+1=2.5取整为2; (2)小数点后数值<0.5不加1取整,如:1.4取整为1 当参数(负数),如下2种情况: (1)小数点后数值>0.5。减1取整,-1.5-1=-2.5,取-2 (2)小数点后数值<=0.5。直接取整,-1.5,取1.5 总结: 正数时(数字越大,值越大),小数>=0.5,进1取大()向上取值;<0.5,向下取值。 负数时(数字越大,值越小),小数>0.5,取小(向下取值);<=0.5,取大
发表于 2022-06-15 09:19:36 回复(0)
Math.round() 四舍五入取大的,题目中是负数,那么就是-2019
发表于 2022-02-07 13:29:55 回复(0)
<p>-2019</p>
发表于 2020-07-05 08:55:23 回复(0)
这个是个数学题,四舍五入
发表于 2020-03-29 13:15:35 回复(0)