cathei / BakingSheet

Easy datasheet management for C# and Unity. Supports Excel, Google Sheet, JSON and CSV format.
MIT License
346 stars 34 forks source link

Incorrect Excel parsing when system decimal separator is a comma #38

Closed tmp64 closed 4 months ago

tmp64 commented 4 months ago

If the system is configured to use decimal separator different from a dot (.), Excel converter parses floats incorrectly.

Source Excel:
image

Converted JSON:
image

I narrowed this down to a ToString call in ExcelSheetConverter.Page.GetCell:

Debugger console:
  _table.Rows[row][col]
  0.29999999999999999

  _table.Rows[row][col].ToString()
  "0,3"

I fixed it like this. Don't know if that's the only place to fix though.

public string GetCell(int col, int row)
{
    if (col >= _table.Columns.Count || row >= _table.Rows.Count)
        return null;

    if (_table.Rows[row][col] is IConvertible conv)
        return conv.ToString(CultureInfo.InvariantCulture);
    else
        return _table.Rows[row][col].ToString();
}

My regional settings for reference:
image

cathei commented 4 months ago

Thank you for reporting! This should've been accounted with https://github.com/cathei/BakingSheet/issues/12, but I overlooked it.

Fixed in v4.1.3

tmp64 commented 4 months ago

Thanks for fixing and releasing so quickly!