Files
freeCodeCamp/guide/chinese/javascript/standard-objects/math/math-trunc/index.md
2018-10-16 21:32:40 +05:30

23 lines
642 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Math Trunc
localeTitle: 数学截尾
---
## 数学截尾
`Math.trunc()`是Math标准对象的一种方法它只通过删除小数单位返回给定数字的整数部分。这导致整体向零舍入。任何非数字的输入都将导致NaN的输出。
小心此方法是ECMAScript 2015ES6功能因此旧版浏览器不支持。
### 例子
```javascript
Math.trunc(0.1) // 0
Math.trunc(1.3) // 1
Math.trunc(-0.9) // -0
Math.trunc(-1.5) // -1
Math.trunc('foo') // NaN
```
### 更多信息:
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)