JavaScript参考手册
Math
Math.fround
ath.fround()
可以将任意的数字转换为离它最近的单精度浮点数形式的数字。
语法
Math.fround(x)
参数
x
一个数值。
返回值
用给定数值的最接近的单精度浮点型表示。
描述
因为fround()
是一个Math
的静态方法且用作Math.fround()
,而不是你创建的Math
对象的方法(Math
不是一个构造函数)。
示例
使用Math.fround()
Math.fround(0); // 0
Math.fround(1); // 1
Math.fround(1.337); // 1.3370000123977661
Math.fround(1.5); // 1.5
Math.fround(NaN); // NaN
Polyfill
下面的函数可以模拟这个 API,但前提是浏览器必须已经支持 Float32Array
:
Math.fround = Math.fround || (function (array) {
return function(x) {
return array[0] = x, array[0];
};
})(Float32Array(1));
规范
Specification |
Status |
Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Math.fround' in that specification. |
Standard |
Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Math.fround' in that specification. |
Draft |
|
浏览器兼容性
Feature |
Chrome |
Firefox |
Edge |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|---|
Basic Support |
38 |
26 |
(Yes) |
(No) |
25 |
7.1 |
Feature |
Android |
Chrome for Android |
Edge mobile |
Firefox for Android |
IE mobile |
Opera Android |
iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support |
(Yes) |
(Yes) |
(Yes) |
26 |
(No) |
(Yes) |
8 |
Math相关
JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络