It's because you're specifying two integers (5 and 2), not floating point values.
Change the code to (in C#):
float f = 5f / 2f;
Console.WriteLine(f);
In most languages, if you don't specify a decimal pointed value (5 instead of 5.0) the value will be treated as an integer. Integer division will never return a floating point value, so you get 2 instead of 2.5.