Quellcode durchsuchen

Merge branch 'feature/fix_excel_decimal' of eta_server/eta_api into debug

baoziqiang vor 5 Monaten
Ursprung
Commit
b037a14875
1 geänderte Dateien mit 12 neuen und 9 gelöschten Zeilen
  1. 12 9
      services/data/excel/mixed_table.go

+ 12 - 9
services/data/excel/mixed_table.go

@@ -1261,19 +1261,23 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
 				err = fmt.Errorf("日期计算配置json解析失败失败: %s, Err:%s", config, err.Error())
 				return
 			}
+			hasPercent := false
+			if styleConf.Nt == "percent" || isPercent {
+				hasPercent = true
+			}
 			if styleConf.Pn != 0 || styleConf.Nt != "" {
 				val := changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, isPercent)
 				cell.ShowFormatValue = val
 				// 修复历史数据,没有保存小数位数, 重置小数位数
-				styleConf.Decimal = new(int)
-				hasPercent := false
-				if styleConf.Nt == "percent" || isPercent {
-					hasPercent = true
+				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)
 				}
-				*styleConf.Decimal = getDecimalLen(val, hasPercent)
-				styleConf.Pn = 0
 			} else if styleConf.Decimal != nil {
-				cell.ShowFormatValue = roundNumber(cell.ShowValue, *styleConf.Decimal)
+				cell.ShowFormatValue = roundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
 			} else {
 				cell.ShowFormatValue = cell.ShowValue
 			}
@@ -1302,8 +1306,7 @@ func getDecimalLen(str string, isPercent bool) (decimalPlaces int) {
 	return
 }
 
-func roundNumber(num string, decimalPlaces int) string {
-	hasPercent := false
+func roundNumber(num string, decimalPlaces int, hasPercent bool) string {
 	if strings.Contains(num, "%") {
 		hasPercent = true
 		num = strings.Trim(num, "%")