时间:2021-07-01 10:21:17 帮助过:44人阅读

我们首先来看一下trunc() 函数的基本语法
Math.trunc(value)
value表示任意数字。
注意:传入该方法的参数会被隐式转换成数字类型。
下面我们来看具体的示例
代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
// 正数浮点类型作为参数传递时
document.write(Math.trunc(15.56)+"<br/>");
// 负数浮点类型作为参数传递时
document.write(Math.trunc(-15.56)+"<br/>");
// 0到1之间的正数作为参数传递时
document.write(Math.trunc(0.236)+"<br/>");
// 0到-1之间的负数作为参数传递时
document.write(Math.trunc(-0.236));
</script>
</script>
</body>
</html>运行的结果如下
15 -15 0 0
本篇文章到这里就全部结束了,更多精彩内容大家可以关注Gxl网的其他相关栏目教程!!!
以上就是trunc函数怎么使用的详细内容,更多请关注Gxl网其它相关文章!