cathei / BakingSheet

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

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

Closed tmp64 closed 3 months ago

tmp64 commented 3 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 3 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 3 months ago

Thanks for fixing and releasing so quickly!