Bizarre calcs

Anomalies in Javascript number representations

by Alon Rotem

HTML

<input type="button" value="0.1 + 0.2 =" onclick="alert(0.1 + 0.2);" /> <br/><br/>

<input type="button" value="(0.1 + 0.2) + 0.3 =" onclick="alert((0.1 + 0.2) + 0.3);" /> <br/><br/>

<input type="button" value="0.1 + (0.2 + 0.3) =" onclick="alert(0.1 + (0.2 + 0.3));" /> <br/><br/>

Rounding:<br/>

<input type="button" value="Math.floor(733663.65) =" onclick="alert(Math.floor(733663.65));" /> (down)
<br/>
<input type="button" value="Math.ceil(733663.65) =" onclick="alert(Math.ceil(733663.65));" /> (up)
<br/>
<input type="button" value="Math.round(733663.35) =" onclick="alert(Math.round(733663.35));" /> (down)
<br/>
<input type="button" value="Math.round(733663.65) =" onclick="alert(Math.round(733663.65));" /> (up)
<br/><br/>
With a bitwse Or operator:
<input type="button" value="733663.65 | 0 =" onclick="alert(733663.65 | 0);" /><br/><br/>

(But wouldn't work on numbers beyond 32 bits range):<br/>
<input type="button" value="Math.floor(3000000000.1) =" onclick="alert(Math.floor(3000000000.1));" /> 
vs.
<input type="button" value="3000000000.1 | 0 =" onclick="alert(3000000000.1 | 0);" />

JavaScript

//alert(isNaN(parseInt("aaa")));

a = 7;
function func()
{
    var a = 5;
    alert(a);
}
func();
//alert(a);