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



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


Posted by 파노카페
: