summaryrefslogtreecommitdiff
path: root/calc.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-09-28 00:04:17 +0800
committerxuri <xuri.me@gmail.com>2022-09-28 00:04:17 +0800
commitefcf599dfe2ec25f10c4d55513a5648addfe989b (patch)
tree29da05dfcac18cbe2712ca8821376be4777c032d /calc.go
parentaddcc1a0b257d3b71e33891891c3a3df4d34f0dc (diff)
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
Diffstat (limited to 'calc.go')
-rw-r--r--calc.go20
1 files changed, 12 insertions, 8 deletions
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 {