Puzzle
C#
Type convertation
Why 15 / 10 is not equal to 1.5?
static void Main(string[] args)
{
int i1 = 15;
int i2 = 10;
float f1 = i1/i2;
Console.WriteLine("{0}", f1);
Console.ReadLine();
}
JavaScript
Floating Point
Why 0.1 + 0.2 is not equal to 0.3?
alert(0.1 + 0.2 === 0.3)
Answer:
Binary floating-points numbers are inept at handling decimal fractions. 0.1 + 0.2 is equal to 0.30000000000000004
NaN
What should we stand instead of '?' for take Bingo?
var v = ?;
if (v !== v) {
alert('Bingo!');
}
Answer:
var v = NaN;
Links
page revision: 7, last edited: 10 Jan 2013 19:26