From 07be99363156b2d1011954be7b5a4cc8f33b256b Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 18 Feb 2022 00:02:39 +0800 Subject: Fixed parsing decimal precision issue --- cell.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'cell.go') diff --git a/cell.go b/cell.go index b6ddd35..b44ed82 100644 --- a/cell.go +++ b/cell.go @@ -1082,23 +1082,23 @@ func (f *File) getCellStringFunc(sheet, axis string, fn func(x *xlsxWorksheet, c // it is possible to apply a format to the cell value, it will do so, if not // then an error will be returned, along with the raw value of the cell. func (f *File) formattedValue(s int, v string, raw bool) string { - precise := v - isNum, precision := isNumeric(v) - if isNum && precision > 10 { - precise = roundPrecision(v, -1) - } if raw { return v } - if !isNum { - v = roundPrecision(v, 15) - precise = v + precise := v + isNum, precision := isNumeric(v) + if isNum { + if precision > 15 { + precise = roundPrecision(v, 15) + } + if precision <= 15 { + precise = roundPrecision(v, -1) + } } if s == 0 { return precise } styleSheet := f.stylesReader() - if s >= len(styleSheet.CellXfs.Xf) { return precise } @@ -1116,7 +1116,7 @@ func (f *File) formattedValue(s int, v string, raw bool) string { } for _, xlsxFmt := range styleSheet.NumFmts.NumFmt { if xlsxFmt.NumFmtID == numFmtID { - return format(v, xlsxFmt.FormatCode) + return format(precise, xlsxFmt.FormatCode) } } return precise -- cgit v1.2.1