'개발관련/Javascript'에 해당되는 글 65건

  1. 2012.10.24 [JavaScript]All JavaScript Numbers are 64-bit!!!

참고: 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:

Example

var x=0.2+0.1;

Try it yourself »



1
2
3
4
5
6
7
8
9
10
11
12
var x;
document.write("<p>Only 17 digits: ");
x=12345678901234567890;
document.write(x + "</p>");
 
document.write("<p>0.2 + 0.1 = ");
x=0.2+0.1;
document.write(x + "</p>");
 
document.write("<p>It helps multiplying and dividing by 10: ");
x=(0.2*10+0.1*10)/10;
document.write(x +"</p>");


이에 대한 결과: 


Only 17 digits: 12345678901234567000

0.2 + 0.1 = 0.30000000000000004

It helps multiplying and dividing by 10: 0.3


Posted by 파노카페
: