From 599a8cb0bceb6cb14d3018360bb4c5140753c2b3 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 19 Nov 2020 21:38:35 +0800 Subject: Fixed #727, rounding numeric with precision for formula calculation --- calc.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'calc.go') 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 } -- cgit v1.2.1