Skip to content
Prev 243238 / 398500 Next

unexpected behavior using round to 2 digits on randomly generated numbers

On 28/11/2010 4:20 PM, Cory Rieth wrote:
This is presumably another version of FAQ 7.31.  Very few numbers of the 
form n/100 are exactly representable in floating point, and the rounding 
error sometimes shows up when you multiply by 100.  A simpler version of 
this is the following:

 > y <- 1:99
 > y[(y/100)*100 != y]
[1]  7 14 28 29 55 56 57 58

Duncan Murdoch