This closes #848 and closes #852, fix reading decimals precision

v2
xuri 4 years ago
parent b14b74bf56
commit f62c45fe0c
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -378,7 +378,7 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) {
return f.formattedValue(c.S, c.V), nil return f.formattedValue(c.S, c.V), nil
default: default:
isNum, precision := isNumeric(c.V) isNum, precision := isNumeric(c.V)
if isNum && precision > 15 { if isNum && precision > 10 {
val, _ := roundPrecision(c.V) val, _ := roundPrecision(c.V)
if val != c.V { if val != c.V {
return f.formattedValue(c.S, val), nil return f.formattedValue(c.S, val), nil

@ -851,22 +851,24 @@ func TestGetValueFromInlineStr(t *testing.T) {
} }
func TestGetValueFromNumber(t *testing.T) { func TestGetValueFromNumber(t *testing.T) {
c := &xlsxC{T: "n", V: "2.2200000000000002"} c := &xlsxC{T: "n"}
f := NewFile() f := NewFile()
d := &xlsxSST{} d := &xlsxSST{}
val, err := c.getValueFrom(f, d) for input, expected := range map[string]string{
assert.NoError(t, err) "2.2.": "2.2.",
assert.Equal(t, "2.22", val) "1.1000000000000001": "1.1",
"2.2200000000000002": "2.22",
c = &xlsxC{T: "n", V: "2.220000ddsf0000000002-r"} "28.552": "28.552",
val, err = c.getValueFrom(f, d) "27.399000000000001": "27.399",
assert.NoError(t, err) "26.245999999999999": "26.246",
assert.Equal(t, "2.220000ddsf0000000002-r", val) "2422.3000000000002": "2422.3",
"2.220000ddsf0000000002-r": "2.220000ddsf0000000002-r",
c = &xlsxC{T: "n", V: "2.2."} } {
val, err = c.getValueFrom(f, d) c.V = input
assert.NoError(t, err) val, err := c.getValueFrom(f, d)
assert.Equal(t, "2.2.", val) assert.NoError(t, err)
assert.Equal(t, expected, val)
}
} }
func TestErrSheetNotExistError(t *testing.T) { func TestErrSheetNotExistError(t *testing.T) {

Loading…
Cancel
Save