I have an excel file that has a column with several values, including NULL, 1.17, 1.19 and 2.01. When I do:
read.xlsx("myExcelFile.xlsx",sheet=1)
Most values in that column remain the same but the 2.01 changes to 2.0099999999999998
I am using openxlsx_4.2.5 with R 4.1.2
Any ideas on why this is happening? suggestions on how to have the 2.01 remain 2.01?
Answer
Thanks to insights from the commenters, this is actually something in excel where it is storing 2.01 to 2.009999999999998 due to the floating points reasons, so the source of the issue is not R or openxlsx but rather starts in Excel itself. The problem was solved by having openxlsx not read the column as a string: read.xlsx(..., na.strings = c('NA', 'NULL'))
. Thanks to the commenters!