Display of Computer Math Glitches With JavaScript


// the binary float
alert(
 "the binary float\n" +
 "0.1 + 0.2 = " + (0.1 + 0.2)
);

// float false Boolean
alert(
 "float false Boolean\n" +
 "(0.1 + 0.2 == 0.3) = " +
  (0.1 + 0.2 == 0.3)
);

// the decimal to string
alert(
  "the decimal to string\n" +
  "parseInt(0.000005) = " +
  (parseInt(0.000005)) +
  "\nparseInt(0.0000005) = " +
  (parseInt(0.0000005))
);

// rounding up/down
alert("rounding up/down\n" +
"(0.235).toFixed(2) = " +
((0.235).toFixed(2)) +
"\n(0.335).toFixed(2) = " +
((0.335).toFixed(2))
);

// sequel of Y2K
msFromEpoch = 2147483647;
alert(
"sequel of Y2K\n" +
"new Date(msFromEpoch*1000).toString()\n"+
(new Date(msFromEpoch*1000).toString()) +
'\n\nmiliseconds from\n'+
(new Date(0).toString())
);