freeCodeCamp/guide/chinese/javascript/standard-objects/math/math-trunc/index.md

23 lines
642 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
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)