首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Math.fround

ath.fround()?可以将任意的数字转换为离它最近的单精度浮点数形式的数字。

语法

代码语言:javascript
复制
Math.fround(x)

参数

x一个数值。

返回值

用给定数值的最接近的单精度浮点型表示。

描述

因为fround()是一个Math的静态方法且用作Math.fround(),而不是你创建的Math对象的方法(Math不是一个构造函数)。

示例

使用Math.fround()

代码语言:javascript
复制
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

代码语言:javascript
复制
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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com