Why does this occur:
window.onload = function(){
var bob=new Number(1);
for (var i=0; i<8 ;i++){
bob=Number(bob+1.1)
}
}
Alerts:
2.1
3.2
4.300000000000001
5.4
6.5
7.6
8.7
9.799999999999999
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s rounding issues.
4.3has no exact representation in binary.How exactly numbers get stored in JavaScript is actually implementation-specific, but it is always a binary floating point.
Edit:
Looks like my information is a little outdated. The standard now specifies doubleprecision 64-bit format IEEE 754 values
Links:
offical PDF
HTML version