Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用math.abs删除负数,但使用条带小数_Javascript_Ecmascript 6 - Fatal编程技术网

Javascript 使用math.abs删除负数,但使用条带小数

Javascript 使用math.abs删除负数,但使用条带小数,javascript,ecmascript-6,Javascript,Ecmascript 6,Math.abs(-101.2)//101.2 但是如何去掉小数点呢?我是否应该使用另一个像round这样的数学函数来包装上述方法?您可以使用 设x=Math.floor(Math.abs(-101.2)); console.log(x)根据需要使用地板或天花板 var x = Math.floor(Math.abs(-101.2)); //makes x=101 var y = Math.ceil(Math.abs(-101.2)); //makes y=102 您可以将Math.abs括

Math.abs(-101.2)//101.2


但是如何去掉小数点呢?我是否应该使用另一个像round这样的数学函数来包装上述方法?

您可以使用
设x=Math.floor(Math.abs(-101.2));

console.log(x)
根据需要使用地板或天花板

var x = Math.floor(Math.abs(-101.2)); //makes x=101

var y = Math.ceil(Math.abs(-101.2)); //makes y=102

您可以将
Math.abs
括在
parseInt

var a=parseInt(Math.abs(-101.2));//101.2

控制台日志(a)“我应该使用另一个像round这样的数学函数来包装上述方法吗?”-是的,确切地说,您期望得到什么结果?让我们考虑一下value
-101.9
-您期望得到什么值<代码>101
102