[JavaScript]All JavaScript Numbers are 64-bit!!!
개발관련/Javascript 2012. 10. 24. 21:29 |참고: http://www.w3schools.com/js/js_obj_number.asp
All JavaScript Numbers are 64-bit
JavaScript is not a typed language. Unlike many other programming languages, it does not define different types of numbers, like integers, short, long, floating-point etc.
All numbers in JavaScript are stored as 64-bit (8-bytes) base 10, floating point numbers.
Precision
Integers (numbers without a period or exponent notation) are considered accurate up to 15 digits.
The maximum number of decimals is 17, but floating point arithmetic is not always 100% accurate:
var x; document.write("Only 17 digits: "); x=12345678901234567890; document.write(x + "
"); document.write("0.2 + 0.1 = "); x=0.2+0.1; document.write(x + "
"); document.write("It helps multiplying and dividing by 10: "); x=(0.2*10+0.1*10)/10; document.write(x +"
");
이에 대한 결과:
Only 17 digits: 12345678901234567000
0.2 + 0.1 = 0.30000000000000004
It helps multiplying and dividing by 10: 0.3
'개발관련 > Javascript' 카테고리의 다른 글
자바스크립트에서의 상수 선언 (0) | 2013.03.27 |
---|---|
자바스크립트의 세 가지 기본 데이터 타입 (0) | 2013.03.27 |
[Javascript]자바스크립트 Code Quality Checker - JSLint (0) | 2012.03.19 |
[Javascript]Javascript Minification (0) | 2012.03.19 |
[자바스크립트]쿠키 삭제하기 (0) | 2012.03.11 |