summaryrefslogtreecommitdiff
path: root/calc.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-11-19 21:38:35 +0800
committerxuri <xuri.me@gmail.com>2020-11-19 21:38:35 +0800
commit599a8cb0bceb6cb14d3018360bb4c5140753c2b3 (patch)
tree30128b1d6c475db2719cce3e811bef826e8a20d1 /calc.go
parent92c8626f814c3bcb91e30f83de8e68c9b8bb9a5f (diff)
Fixed #727, rounding numeric with precision for formula calculation
Diffstat (limited to 'calc.go')
-rw-r--r--calc.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/calc.go b/calc.go
index bc3b6e9..577cfaa 100644
--- a/calc.go
+++ b/calc.go
@@ -42,6 +42,14 @@ const (
formulaErrorGETTINGDATA = "#GETTING_DATA"
)
+// Numeric precision correct numeric values as legacy Excel application
+// https://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft_Excel In the
+// top figure the fraction 1/9000 in Excel is displayed. Although this number
+// has a decimal representation that is an infinite string of ones, Excel
+// displays only the leading 15 figures. In the second line, the number one
+// is added to the fraction, and again Excel displays only 15 figures.
+const numericPrecision = 1000000000000000
+
// cellRef defines the structure of a cell reference.
type cellRef struct {
Col int
@@ -141,6 +149,13 @@ func (f *File) CalcCellValue(sheet, cell string) (result string, err error) {
return
}
result = token.TValue
+ if len(result) > 16 {
+ num, e := roundPrecision(result)
+ if e != nil {
+ return result, err
+ }
+ result = strings.ToUpper(num)
+ }
return
}