Originally posted by bruceg
> I tried
round(11.5) and I get 12
round(182.5) and I get 182...
You are right.
It could be a bug in the round() function.
This is normal and reflects how computers store floating point numbers.
11.5 is not actually 11.5.
There are two errors in the statements above. There is no bug. First, a round function which rounds odd numbers up and even numbers down is called bankers rounding. It is done that way because of the distribution of integers above and below the "breakpoint" number 0.5. 0,1,2,3,4 = 5 integers. 5,6,7,8,9 = 5 integers. Values of exactly 0.5 always go the nearest even number, so there is an even distribution of "up" and "down" rounding.
Second, 11.5 can be represented as EXACTLY as 11.5 in any standard floating point field in use on computers today. Here is a small tutorial on why some floating point numbers can be represented exactly, while others cannot.
It is not possible to exactly represent many decimal fractions in a binary float field. For example, 0.1 cannot be represented exactly in a 32 bit float with a 23 bit mantissa. It is not the number of decimal digits, but rather whether the number can be represented in terms of 1 / (2n) where n is the bit position in the mantissa. For example
bit 1 - 1 / (21) = 0.5
bit 2 - 1 / (22) = 0.25
bit 3 - 1 / (23) = 0.125
bit 4 - 1 / (24) = 0.0625
and so on until you get to
bit 23 - 1 / (223) = 0.00000011920928955078125
No matter how you combine the bits you cannot get to 0.1, although you can get close.