Open severinh opened 2 days ago
Hello @severinh
Always great to have a clear bug issue with file and clear explanation thank you!
I checked quickly and indeed it feels hard to fix on fastexcel
side
In src/data.rs
, in create_string_array
function we simply do
cell.as_string()
Even with
cell.get_float().map(|v| v.to_string())
or
cell.as_f64()
we get the same behavior with this floating precision issue and AFAIK there is no way for us to get more info on the original input. I'll try to dig on calamine side tonight
EDIT: quick check on calamine
inner: [
SharedString(
"Decimals",
),
Float(
28.14,
),
Float(
29.020000000000003,
),
],
when reading the xml content we get
BytesText { content: Borrowed("29.020000000000003") }
so I guess it goes even further directly in the xml content 😞
Steps to reproduce
See the Excel file decimal-numbers.xlsx. It contains a column with two decimals:
Read the Excel file using fastexcel:
Looks fine.
Then read the Excel file while casting to strings:
The expected result was that the strings would be the same as shown to the user in the Excel file:
Wrap-up
I understand this looks like an issue due to floating point precision, and I'm not sure if this:
What's the motivation for filing this bug: In our system, we have highly heterogeneous data, so we have to read all Excel values as strings. However, if users see 29.02 in their Excel files, but
29.020000000000003
in our system, that's highly confusing and surprising to users.What do you think?