summaryrefslogtreecommitdiff
path: root/rows.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-10-15 21:45:46 +0800
committerxuri <xuri.me@gmail.com>2021-10-15 21:45:46 +0800
commitde38402f74bea9557188ad2c6f31c3127fd1bbfe (patch)
tree6c9363697638d1b78012a80bc6ce0fb45181e4bc /rows.go
parent58fd279dc845ebd9ccd4ba336d7c664824e70e43 (diff)
This closes #1031, fix small float parsed error in some case
- new formula function: YEARFRAC, ref #65 - update the codecov version - remove unused variable
Diffstat (limited to 'rows.go')
-rw-r--r--rows.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/rows.go b/rows.go
index 3d8c247..3171ab1 100644
--- a/rows.go
+++ b/rows.go
@@ -18,6 +18,7 @@ import (
"io"
"log"
"math"
+ "math/big"
"os"
"strconv"
@@ -421,14 +422,19 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST, raw bool) (string, error) {
}
}
-// roundPrecision round precision for numeric.
-func roundPrecision(value string) (result string, err error) {
- var num float64
- if num, err = strconv.ParseFloat(value, 64); err != nil {
- return
+// roundPrecision provides a function to format floating-point number text
+// with precision, if the given text couldn't be parsed to float, this will
+// return the original string.
+func roundPrecision(text string, prec int) string {
+ decimal := big.Float{}
+ if _, ok := decimal.SetString(text); ok {
+ flt, _ := decimal.Float64()
+ if prec == -1 {
+ return decimal.Text('G', 15)
+ }
+ return strconv.FormatFloat(flt, 'f', -1, 64)
}
- result = fmt.Sprintf("%g", math.Round(num*numericPrecision)/numericPrecision)
- return
+ return text
}
// SetRowVisible provides a function to set visible of a single row by given