|
@@ -1186,11 +1186,12 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
|
|
|
|
|
|
cell := config[cellPosition.Column][cellPosition.Row]
|
|
cell := config[cellPosition.Column][cellPosition.Row]
|
|
val := cell.ShowValue
|
|
val := cell.ShowValue
|
|
- isPercent := false
|
|
+
|
|
- if strings.Contains(val, "%") {
|
|
+
|
|
- isPercent = true
|
|
+
|
|
- val = strings.Trim(val, "%")
|
|
+
|
|
- }
|
|
+
|
|
|
|
+
|
|
_, e := strconv.ParseFloat(val, 64)
|
|
_, e := strconv.ParseFloat(val, 64)
|
|
if e != nil {
|
|
if e != nil {
|
|
var styleConf request.MixCellShowStyle
|
|
var styleConf request.MixCellShowStyle
|
|
@@ -1216,19 +1217,39 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
|
|
err = fmt.Errorf("日期计算配置json解析失败失败: %s, Err:%s", config, err.Error())
|
|
err = fmt.Errorf("日期计算配置json解析失败失败: %s, Err:%s", config, err.Error())
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ hasPercent := false
|
|
|
|
+ if styleConf.Nt == "percent" {
|
|
|
|
+ hasPercent = true
|
|
|
|
+ }
|
|
if styleConf.Pn != 0 || styleConf.Nt != "" {
|
|
if styleConf.Pn != 0 || styleConf.Nt != "" {
|
|
- val = changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, isPercent)
|
|
+ val := changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, hasPercent)
|
|
cell.ShowFormatValue = val
|
|
cell.ShowFormatValue = val
|
|
|
|
+
|
|
|
|
+ if styleConf.Pn > 0 {
|
|
|
|
+ styleConf.Decimal = new(int)
|
|
|
|
+ *styleConf.Decimal = getDecimalLen(val, hasPercent)
|
|
|
|
+ styleConf.Pn = 0
|
|
|
|
+ } else if styleConf.Decimal != nil {
|
|
|
|
+ cell.ShowFormatValue = roundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
|
|
|
|
+ } else {
|
|
|
|
+ if hasPercent {
|
|
|
|
+ numDecimal, _ := decimal.NewFromString(cell.ShowValue)
|
|
|
|
+ tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
|
|
|
|
+ cell.ShowFormatValue = tmpStr + "%"
|
|
|
|
+ } else {
|
|
|
|
+ cell.ShowFormatValue = cell.ShowValue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if styleConf.Decimal != nil {
|
|
|
|
+ cell.ShowFormatValue = roundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
|
|
} else {
|
|
} else {
|
|
cell.ShowFormatValue = cell.ShowValue
|
|
cell.ShowFormatValue = cell.ShowValue
|
|
}
|
|
}
|
|
|
|
|
|
- if styleConf.GlObj != nil {
|
|
+ styleConf.GlObj = nil
|
|
- styleConf.GlObj = nil
|
|
+ tmpStyleConf, err := json.Marshal(styleConf)
|
|
- tmpStyleConf, err := json.Marshal(styleConf)
|
|
+ if err == nil {
|
|
- if err == nil {
|
|
+ cell.ShowStyle = string(tmpStyleConf)
|
|
- cell.ShowStyle = string(tmpStyleConf)
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
config[cellPosition.Column][cellPosition.Row] = cell
|
|
config[cellPosition.Column][cellPosition.Row] = cell
|
|
}
|
|
}
|
|
@@ -1236,6 +1257,32 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func getDecimalLen(str string, isPercent bool) (decimalPlaces int) {
|
|
|
|
+ dotIndex := strings.Index(str, ".")
|
|
|
|
+ if dotIndex == -1 {
|
|
|
|
+ decimalPlaces = 0
|
|
|
|
+ } else {
|
|
|
|
+ decimalPlaces = len(str) - dotIndex - 1
|
|
|
|
+ }
|
|
|
|
+ if isPercent && decimalPlaces >= 1 {
|
|
|
|
+ decimalPlaces -= 1
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func roundNumber(num string, decimalPlaces int, hasPercent bool) string {
|
|
|
|
+ numDecimal, _ := decimal.NewFromString(num)
|
|
|
|
+ if hasPercent {
|
|
|
|
+ numDecimal = numDecimal.Mul(decimal.NewFromInt(100))
|
|
|
|
+ }
|
|
|
|
+ numFloat, _ := numDecimal.Round(int32(decimalPlaces)).Float64()
|
|
|
|
+ numStr := strconv.FormatFloat(numFloat, 'f', decimalPlaces, 64)
|
|
|
|
+ if hasPercent {
|
|
|
|
+ numStr += "%"
|
|
|
|
+ }
|
|
|
|
+ return numStr
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
func changePointDecimalPlaces(str string, changeNum int, numberType string, isPercent bool) (newStr string) {
|
|
func changePointDecimalPlaces(str string, changeNum int, numberType string, isPercent bool) (newStr string) {
|
|
newStr = str
|
|
newStr = str
|