Number 객체는 숫자 값으로 작업할 수 있게 해주는 래퍼wrapper 객체입니다. Number 객체는 Number() 생성자를 사용하여 만듭니다. 원시 숫자 자료형은 Number() 함수를 사용해 생성합니다.

구문

new Number(value); 
var a = new Number('123'); // a === 123은 false
var b = Number('123'); // b === 123은 true
a instanceof Number; // false
b instanceof Number; // true

매개변수

value
생성할 객체의 숫자 값.

설명

Number 객체의 주된 용도는 다음과 같습니다.

  • 만약 인수를 숫자로 변환할 수 없으면 NaN을 리턴합니다.
  • 생성자로써 사용하지 않으면(new 연산자를 사용하지 않으면) Number를 사용하여 형변환을 할 수 있습니다.

속성

Number.EPSILON
두 개의 표현 가능한 숫자 사이의 최소 간격.
Number.MAX_SAFE_INTEGER
JavaScript에서 안전한 최대 정수. (253 - 1)
Number.MAX_VALUE
표현 가능한 가장 큰 양수.
Number.MIN_SAFE_INTEGER
JavaScript에서 안전한 최소 정수. (-(253 - 1))
Number.MIN_VALUE
표현 가능한 가장 작은 양수. 즉, 0보다 크지만 0에 가장 가까운 양수.
Number.NaN
"숫자가 아님"을 나타내는 특별한 값.
Number.NEGATIVE_INFINITY
음의 무한대를 나타내는 특수한 값. 오버플로우 시 반환됩니다.
Number.POSITIVE_INFINITY
양의 무한대를 나타내는 특수한 값. 오버플로우 시 반환됩니다.
Number.prototype
Number 객체에 속성을 추가할 수 있습니다.

메서드

Number.isNaN()
주어진 값이 NaN인지 확인합니다.
Number.isFinite()
주어진 값이 유한수 인지 확인합니다.
Number.isInteger()
주어진 값이 정수인지 확인합니다.
Number.isSafeInteger()
주어진 값이 안전한 정수(-(253 - 1)과 253 - 1 사이의 정수)인지 확인합니다.
Number.toInteger()
전달 된 값을 평가하고 이를 정수(혹은 Infinity)로 변환하는데 사용되지만, 제거되었습니다.
Number.parseFloat()
전역 객체 parseFloat()와 동일한 값입니다.
Number.parseInt()
전역 객체 parseInt()와 동일한 값입니다.

Number 인스턴스

모든 Number 인스턴스는 Number.prototype를 상속합니다. Number 생성자의 프로토타입 객체는 모든 Number 인스턴스에 영향을 미치도록 수정할 수 있습니다.

메서드

예제

Number 객체를 사용해 숫자형 변수에 할당

다음 예제에서는 Number 객체의 속성을 사용하여, 여러 숫자 변수에 값을 할당합니다:

var biggestNum = Number.MAX_VALUE;
var smallestNum = Number.MIN_VALUE;
var infiniteNum = Number.POSITIVE_INFINITY;
var negInfiniteNum = Number.NEGATIVE_INFINITY;
var notANum = Number.NaN;

Number의 정수 범위

다음 예제는 Number 객체가 표현할 수 있는 정수의 최소값과 최대값을 보여줍니다. (자세한 내용은 ECMAScript 표준, 6.1.6 The Number Type 장을 참고하세요)

var biggestInt = 9007199254740992;
var smallestInt = -9007199254740992;

JSON으로 직렬화한 데이터를 읽을 때, 위의 범위를 벗어나는 수는 JSON 분석기의 Number 형변환 시 손상될 수 있습니다. 이 때는 String을 대신 사용하는 것도 방법입니다.

Number를 사용해 Date 객체 숫자로 변환

다음 예제는 Number를 함수로 사용하여 Date 객체를 숫자 값으로 변환합니다.

var d = new Date('December 17, 1995 03:24:00');
console.log(Number(d));

819199440000가 기록됩니다.

숫자형 문자열에서 숫자로 변환

Number('123')     // 123
Number('12.3')    // 12.3
Number('123e-1')  // 12.3
Number('')        // 0
Number(null)      // 0 
Number('0x11')    // 17
Number('0b11')    // 3
Number('0o11')    // 9
Number('foo')     // NaN
Number('100a')    // NaN

명세

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Number' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Number' in that specification.
Standard New methods and properties added: (EPSILON, isFinite, isInteger, isNaN, parseFloat, parseInt)
ECMAScript Latest Draft (ECMA-262)
The definition of 'Number' in that specification.
Draft  

브라우저 호환성

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
NumberChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
EPSILONChrome Full support YesEdge Full support YesFirefox Full support 25IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.12
MAX_SAFE_INTEGERChrome Full support 34Edge Full support YesFirefox Full support 31IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 31Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.12
MAX_VALUEChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
MIN_SAFE_INTEGERChrome Full support 34Edge Full support YesFirefox Full support 31IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 31Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.12
MIN_VALUEChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
NEGATIVE_INFINITYChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
NaNChrome Full support YesEdge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
POSITIVE_INFINITYChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
isFiniteChrome Full support 19Edge Full support 12Firefox Full support 16IE No support NoOpera Full support 15Safari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 16Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support 0.10
isIntegerChrome Full support YesEdge Full support 12Firefox Full support 16IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 16Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support 0.12
isNaNChrome Full support 25Edge Full support 12Firefox Full support 15IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 15Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.10
isSafeIntegerChrome Full support YesEdge Full support 12Firefox Full support 32IE No support NoOpera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 32Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support 0.12
parseFloatChrome Full support YesEdge Full support 12Firefox Full support 25IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.12
parseIntChrome Full support YesEdge Full support 12Firefox Full support 25IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.12
prototypeChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
toExponentialChrome Full support YesEdge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
toFixedChrome Full support YesEdge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
toInteger
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 16 — 32IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 16 — 32Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
toLocaleStringChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
toPrecisionChrome Full support YesEdge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
toSource
Non-standard
Chrome No support NoEdge No support NoFirefox Full support 1IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 4Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
toStringChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
valueOfChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support
No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

같이 보기

문서 태그 및 공헌자

이 페이지의 공헌자: mdnwebdocs-bot, alattalatta, DeadIntegral, taeunChoi, ChoeSul, fscholz
최종 변경자: mdnwebdocs-bot,