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

생성자

new Number(value);

매개변수

value
생성되는 객체의 숫자값.

설명

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

  • 만약 인수(argument)를 숫자로 변환할 수 없으면, NaN을 리턴합니다.
  • 생성자가 아닌 컨텍스트(즉, new 연산자를 사용하지 않은) 에서는 Number 를 사용하여 타입 변환을 수행할 수 있습니다.

속성

Number.EPSILON
두 개의 표현 가능한 숫자 사이의 최소 간격.
Number.MAX_SAFE_INTEGER
자바스크립트에서 안전한 최대 정수 (253 - 1).
Number.MAX_VALUE
표현 가능한 가장 큰 양수.
Number.MIN_SAFE_INTEGER
자바스크립트에서 안전한 최소 정수 (-(253 - 1)).
Number.MIN_VALUE
표현 가능한 가장 작은 양수 - 즉, 0에 가장 가까운 양수(0이 아님).
Number.NaN
숫자가 아님을 나타내는 특별한 값 "not a number".
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.prototype.toExponential()
지수 표기법으로 숫자의 표현을 문자열로 반환합니다.
Number.prototype.toFixed()
고정 소수점 표기법으로 숫자의 표현을 문자열로 반환합니다.
Number.prototype.toLocaleString()
이 숫자의 표현을 특정 언어에 맞춘 형식의 문자열로 반환합니다. Object.prototype.toLocaleString() 메서드를 오버라이드(ovveride) 합니다.
Number.prototype.toPrecision()
고정 소수점 혹은 지수 표기법으로, 지정한 정밀도로 숫자를 나타내는 문자열을 반환합니다.
Number.prototype.toSource()
지정한 Number 객체를 나타내는 객체 리터럴을 반환합니다; 이 값을 사용하여 새 객체를 만들 수 있습니다. Object.prototype.toSource() 메서드를 오버라이드 합니다.
Number.prototype.toString()
지정된 기수(기본 10진수)로 지정된 객체를 문자열로 반환합니다. Object.prototype.toString() 메서드를 오버라이드 합니다.
Number.prototype.valueOf()
지정한 객체의 기본(primitive) 타입을 반환합니다. Object.prototype.valueOf() 메서드를 오버라이드 합니다.

예제

Using the Number object to assign values to numeric variables

다음 예제에서는 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;

Integer range for Number

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

var biggestInt = 9007199254740992;
var smallestInt = -9007199254740992;

JSON으로 직렬화된 데이터를 파싱할 때, JSON 파서가 Number 타입으로 강제 변환할 때 이 범위를 벗어나는 정수값은 손상될 수 있습니다. 대신에 String를 사용하여 해결할 수 있습니다.

Using Number to convert a Date object

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

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

이것은 "819199440000" 가 찍힙니다.

Convert numeric strings to numbers

Number("123")     // 123
Number("")        // 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 AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome 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 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
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 YesFirefox 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 YesFirefox 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 YesFirefox 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 YesFirefox 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 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
parseIntChrome 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
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 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
toFixedChrome 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
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 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
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.

 

같이 보기

문서 태그 및 공헌자

이 페이지의 공헌자: DeadIntegral, urty5656, taeunChoi, ChoeSul, fscholz
최종 변경자: DeadIntegral,