Math.fround()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Math.fround() 함수는 single precision 포맷으로 표현할 수 있는 실수들 중에서 가장 가까운 숫자를 리턴합니다.

문법

js
Math.fround(x);

파라메터

x

숫자.

설명

fround()Math 객체의 정적 메소드이기 때문에, 반드시 Math.fround() 같은 형태로 사용해야 합니다. Math 객체를 직접 만들어서 호출하는 방식으로 사용하지 않습니다 (Math 는 생성자가 아닙니다).

예제

Math.fround() 사용법

js
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

만약 Float32Array 가 지원된다면, Math.fround() 를 다음 함수로 흉내낼 수 있습니다.

js
Math.fround =
  Math.fround ||
  (function (array) {
    return function (x) {
      return (array[0] = x), array[0];
    };
  })(Float32Array(1));

명세

Specification
ECMAScript® 2025 Language Specification
# sec-math.fround

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
fround

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also