From efcf599dfe2ec25f10c4d55513a5648addfe989b Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 28 Sep 2022 00:04:17 +0800 Subject: This closes #1360, closes #1361 - Fix default number format parse issue with a long string of digits - Fix creating a sheet with an empty name cause a corrupted file - The `GetCellStyle` function no longer return master cell style of the merge cell range - Using the specialized name in variables and functions --- calc.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'calc.go') diff --git a/calc.go b/calc.go index f7b3a63..b19dba7 100644 --- a/calc.go +++ b/calc.go @@ -789,10 +789,14 @@ func (f *File) calcCellValue(ctx *calcContext, sheet, cell string) (result strin return } result = token.Value() - isNum, precision := isNumeric(result) - if isNum && (precision > 15 || precision == 0) { - num := roundPrecision(result, -1) - result = strings.ToUpper(num) + if isNum, precision, decimal := isNumeric(result); isNum { + if precision > 15 { + result = strings.ToUpper(strconv.FormatFloat(decimal, 'G', 15, 64)) + return + } + if !strings.HasPrefix(result, "0") { + result = strings.ToUpper(strconv.FormatFloat(decimal, 'f', -1, 64)) + } } return } @@ -2089,13 +2093,13 @@ func (fn *formulaFuncs) COMPLEX(argsList *list.List) formulaArg { // cmplx2str replace complex number string characters. func cmplx2str(num complex128, suffix string) string { realPart, imagPart := fmt.Sprint(real(num)), fmt.Sprint(imag(num)) - isNum, i := isNumeric(realPart) + isNum, i, decimal := isNumeric(realPart) if isNum && i > 15 { - realPart = roundPrecision(realPart, -1) + realPart = strconv.FormatFloat(decimal, 'G', 15, 64) } - isNum, i = isNumeric(imagPart) + isNum, i, decimal = isNumeric(imagPart) if isNum && i > 15 { - imagPart = roundPrecision(imagPart, -1) + imagPart = strconv.FormatFloat(decimal, 'G', 15, 64) } c := realPart if imag(num) > 0 { -- cgit v1.2.1