I have to round a data frame to two decimal places and the 1/100s decimal always needs to round up. However I am seeing some odd behavior with the ceiling function that I'm using.
a <- c(268.600, 268.700, 268.500)
b <- c(22.410, 653.423, 124.400)
df1 <- data.frame(a, b)
ceiling(df1 * 100)/100
a b
1 268.61 22.41
2 268.70 653.43
3 268.50 124.40
I expect the output at df1[1,1] to be 268.60 .. but I am getting 268.61. I am not sure why this is happening; the other numerics in 'a' give the expected output. I'm using R version 3.5.3
EDIT:
@Akrun identified the issue in col A as a result of floating point numbers.
What I am looking for help with now is a way to round a number like 10.032 to 10.04 while also avoiding having a number like 10.000 round to 10.01 due to floating point issues.
Right now I am stuck with either having df1[1,1] round correctly or df[2,2] round correctly but not both.