Skip to content

Commit

Permalink
This closes #848 and closes #852, fix reading decimals precision
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Jul 11, 2021
1 parent b14b74b commit f62c45f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) {
return f.formattedValue(c.S, c.V), nil
default:
isNum, precision := isNumeric(c.V)
if isNum && precision > 15 {
if isNum && precision > 10 {
val, _ := roundPrecision(c.V)
if val != c.V {
return f.formattedValue(c.S, val), nil
Expand Down
30 changes: 16 additions & 14 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,22 +851,24 @@ func TestGetValueFromInlineStr(t *testing.T) {
}

func TestGetValueFromNumber(t *testing.T) {
c := &xlsxC{T: "n", V: "2.2200000000000002"}
c := &xlsxC{T: "n"}
f := NewFile()
d := &xlsxSST{}
val, err := c.getValueFrom(f, d)
assert.NoError(t, err)
assert.Equal(t, "2.22", val)

c = &xlsxC{T: "n", V: "2.220000ddsf0000000002-r"}
val, err = c.getValueFrom(f, d)
assert.NoError(t, err)
assert.Equal(t, "2.220000ddsf0000000002-r", val)

c = &xlsxC{T: "n", V: "2.2."}
val, err = c.getValueFrom(f, d)
assert.NoError(t, err)
assert.Equal(t, "2.2.", val)
for input, expected := range map[string]string{
"2.2.": "2.2.",
"1.1000000000000001": "1.1",
"2.2200000000000002": "2.22",
"28.552": "28.552",
"27.399000000000001": "27.399",
"26.245999999999999": "26.246",
"2422.3000000000002": "2422.3",
"2.220000ddsf0000000002-r": "2.220000ddsf0000000002-r",
} {
c.V = input
val, err := c.getValueFrom(f, d)
assert.NoError(t, err)
assert.Equal(t, expected, val)
}
}

func TestErrSheetNotExistError(t *testing.T) {
Expand Down

0 comments on commit f62c45f

Please sign in to comment.