From 94f197c4fe6531f96a42fe4e960c1c921a3ee0e8 Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 19 Mar 2022 00:05:47 +0800 Subject: This improved formula calculate precision and added zero placeholder number format support --- cell.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'cell.go') diff --git a/cell.go b/cell.go index c3b62dc..6ecce4f 100644 --- a/cell.go +++ b/cell.go @@ -1088,22 +1088,12 @@ func (f *File) formattedValue(s int, v string, raw bool) string { if raw { return 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 + return v } styleSheet := f.stylesReader() if s >= len(styleSheet.CellXfs.Xf) { - return precise + return v } var numFmtID int if styleSheet.CellXfs.Xf[s].NumFmtID != nil { @@ -1112,17 +1102,17 @@ func (f *File) formattedValue(s int, v string, raw bool) string { ok := builtInNumFmtFunc[numFmtID] if ok != nil { - return ok(precise, builtInNumFmt[numFmtID]) + return ok(v, builtInNumFmt[numFmtID]) } if styleSheet == nil || styleSheet.NumFmts == nil { - return precise + return v } for _, xlsxFmt := range styleSheet.NumFmts.NumFmt { if xlsxFmt.NumFmtID == numFmtID { - return format(precise, xlsxFmt.FormatCode) + return format(v, xlsxFmt.FormatCode) } } - return precise + return v } // prepareCellStyle provides a function to prepare style index of cell in -- cgit v1.2.1